ShareLinkTask, check if a user has connected to a network - c#

I would like to user the ShareLinkTask in my Windows Phone app to enable users to share a link.
When I test the following code on the emulator:
// share to social networks
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = vine.description;
shareLinkTask.LinkUri = new Uri("link");
shareLinkTask.Message = "I want to share this link";
shareLinkTask.Show();
The emulator goes to a black screen and immediately backs out. I guess this is due to the fact that I haven't connected to a network on the emulator.
So my question is, how do I detect if a user has no connected networks so that I can show an appropriate message?

Do you mean connected to any accounts that could be used for sharing? You could use the Account class to determine if there are any user accounts set up before triggering the task.
Note that doing this requires the ID_CAP_CONTACTS and ID_CAP_APPOINTMENTS which may look weird to your users and seeing that this is an extreme edge case (there are very few phones that do not have any account on them) it may not be worth the extra code / capability requests.
If you do want to iterate accounts you can use:
(new Contacts()).Accounts
and if there is nothing there, there are no accounts.

The behaviour you are seeing on the emulator is because you are not signed in to the phone with a Microsoft account. As such there are no social networks associated that can be used to share the link.

Related

How to identify a mobile User in Unity without an explicit registration

First of all, I have been searching forums for about a year for a viable solution. What I am looking for is a way to identify a mobile User by an ID that is NOT linked to the device.
So no SystemInfo.deviceUniqueIdentifier
My thoughts go out towards identifying Users using the Google Account of the User (Android) or the Apple account (iOS).
What I have tried so far is connecting the application through the GooglePlayGames API. It is successfully connected and works fine. It logs in automatically when I start the application and I retrieve and store the googleId in my database.
The drawback here however is that the app is now dependent on GooglePlayGames, which is something I dislike. I don't like explicit dependencies on other apps. And I also need to find a suitable equivalent for iOS.
I have yet to implement the Unity IAP to enable in app purchasing. I could not find any info on how transactions are linked to Users on android/ iOS. Is there a way to retrieve/store any User related Id during transactions?
It seems to me that when working with in app purchasing, that you need to have some way to reimburse/reactivate purchases made by users when they switch phones for example.
Best case scenario would be an easy way to store an Id without depending on Unity IAP, so that Free To Play Users can also easily recover their account.
You can use Mac Address. This is unique for every device.
string GetMacAddress()
{
string reesult = "";
foreach (NetworkInterface ninf in NetworkInterface.GetAllNetworkInterfaces())
{
if (ninf.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue;
if (ninf.OperationalStatus == OperationalStatus.Up)
{
reesult += ninf.GetPhysicalAddress().ToString();
break;
}
}
return reesult;
}
Now, if the device is jail-broken or tampered with, the Mac Address can be spoofed or temporary changed.
SystemInfo.deviceUniqueIdentifier is not 100% reliable, especially not
on IOS. Furthermore I will lose the connection to the User if he
switches device.
You can use Unity's SocialPlatforms API to check if the user is logged in then obtain the user id. That you can use to determine the user on any device.
Social.localUser.Authenticate(success =>
{
if (success)
{
Debug.Log("Authentication successful");
string userInfo = Social.localUser.id;
Debug.Log(userInfo);
}
else
Debug.Log("Authentication failed");
});
If you really need more control over your users, you should implement your own token-based authentication such as oauth2. It's not really hard to make one yourself if you have background of PHP and MySQL.
For iOS you need to implement the Apple Game Center.
The docs make it look pretty easy, looks like a single function call that will prompt the user to sign in if they're not already signed in.
Should work the same as the Google Play Store API after that.

Windows phone 8 push notification null channel uri

I know this has been brought up many times but couldn't find an answer for it.
I am trying to set up push notifications in my app using the below code however I am running into the channel uri null problem.
I have tried the app on 4 different devices + emulator all under the same network conditions (Work WiFi - Home WiFi - 3G) 2 of the devices are Lumia 920 both could not obtain a channel uri, while the other 2 devices an HTC 8X and a Lumia 820 can successfully obtain channel uri and register for push.
The emulator also can obtain a channel uri successfully.
On one of the Lumia 920's it managed to get a channel uri, but I uninstalled and installed the app again and since then couldn't get any channel uri.
Below are my scenarios:
1- Lumia 920 Black installed on 3G worked fine, uninstalled/reinstalled stopped working on any connection (3G - Work WiFi - Home WiFi)
2- Lumia 920 Yellow installed on 3G - Work WiFi - Home WIfi never managed to get a channel uri
3- HTC 8X on 3G - Work WiFi - Home WiFi worked great on all 3 networks
4- Lumia 820 same as HTC 8X worked great
Please note that push notifications on other apps are working fine on all 4 devices.
I'd greatly appreciate any feedback/advice for the channel null uri
Below is the code I used, it is the same code as provided by MSDN
public MainPage()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "ToastSampleChannel";
InitializeComponent();
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for toast events.
pushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
pushChannel.ChannelUri.ToString()));
}
}
I have also experienced the same issue. And it got resolved by setting my HTC windows phone with correct date and time.Once I set the date and time automatically, My hybrid application wp8 successfully registered pushplugin and received MPNS Channeluri.
The ChannelUri was null because the new phone I was developing on would not set it's date and time correctly. Once I switched the time to be set manually, then fixed it's time, date and region and then switched it back to auto, everything worked fine such as ssl certificates, windows phone update and most importantly a ChannelUri ;)
Try going into settings > "phone + SIM" and turning off the "Data connection" option this sometimes does the trick?
Have you tried changing the options in settings > data sense? There are options there that restrict background data?
Is battery saver enabled? This limits usage when battery is low etc.
Also as mentioned above, Have you checked the date and time on the device? Maybe it's caused by the auto setting of date and time. You can fix this manually then switch back to auto. It works.
Try using a local wifi connection rather than the cell phone data connection. Disabling the phones "Data connection" as per one of the comments here will achieve this result. Although I tried this and failed it lead me to noticed that my phone was not connected to our wifi router.
NOTE: In my case we have very bad cell coverage so we use a special vodafone router that redirects all our cell phone data, calls, etc thru our fixed line Internet connection. Once I bypassed the that router I received a ChannelUri. I also tried the phone/app at work which uses a different cell tower and that was fine.
I tried setting the date manually but to no effect. What ended up working for me was to actually start the phone without the SIM card, shut down, re-insert SIM and start again. This allowed me to get a ChannelUri again.
Suspect this could be related to the suggestion of TripVoltage who suggests toggling the SIM's data connection.

LIVE SDK v5.3 & Window 8 - How to tell the difference between a user logged in with a Microsoft Account and user with a local account?

I'm using the v5.3 Live SDK for a Windows 8 Store App (XAML/C#) and I have a question.
In my app, if the user is logged into Windows using a Microsoft
Account, then I want to grab the firstname/lastname/Microsoft ID.
If they are logged in to Windows using a local account and haven't
logged in to my app, then I want to show a 'Login' button, so they
can enter their Microsoft account email/password.
I know how to do all that using the Live SDK, but my question is - how can I tell if the user is logged into Windows with a Microsoft account versus a Local Account that hasn't been logged in to the MS account?
I can use the following:
var idAuth = new OnlineIdAuthenticator();
return idAuth.CanSignOut;
but this will return false if either the 2 criteria above is true (and return true if the user is using a local account, but has logged in to my app using Microsoft account details).
In theory, if the above returns false, I can do the following:
LiveAuthClient authClient = new LiveAuthClient();
LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.signin" });
if (authResult.Status == LiveConnectSessionStatus.Connected)
{ //Get user info here }
The problem is that this works fine for a user logged into windows using a Microsoft Account - their info is picked up fine, but if it is a user logged into Windows with a local account, then it is going to show the Live Login screen in my app - at that point I don't want to do that, rather just show a logon button in my UI.
Anyone any ideas on how to tell the difference between the 2 criteria above?
Thanks in anticipation,
Richard.
I ended up asking the same question on the MSDN forums and got an answer there, so I am posting it here just in case it helps anyone else.
http://social.msdn.microsoft.com/Forums/en-US/messengerconnect/thread/f6946851-‌​b495-45f6-95a4-eb3c2a004c0e

Bluetooth and C# PC -> Cellphone connection without paring

I'm trying to write simple app, which sends short text message to cellphones in bluetooth adapter range.
My first try is sending files: I can send file from PC to cellphone, but i must enter PIN on cellphone, and on PC.
I would rather to send text messages (something like push message) - is it possible to send it without paring devices?
If isn't possible to send push messages, maybe I can send simple file without requesting PIN ?
I use 32feet library.
Sample code (used to send files to selected device)
static int BTSendFile(string adres, string FileName)
{
Uri uri = new Uri("obex://" + adres + '/' + Path.GetFileName(FileName));
ObexWebRequest req = new ObexWebRequest(uri);
req.ReadFile(FileName);
ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
return (int)rsp.StatusCode;
}
A quick answer would be; NO, you will ALWAYS need some kind of pairing.
But if you take a look at the different kinds of pairing out there, you would see that BT 2.1 supports Secure Simple Pairing (SSP) with the Just Works-mode. This allows you to pair devices (almost) without any user interaction. From Wikipedia:
Just works: As implied by the name, this method just works. No user interaction is required; however, a device may prompt the user to confirm the pairing process. This method is typically used by headsets with very limited IO capabilities, and is more secure than the fixed PIN mechanism which is typically used for legacy pairing by this set of limited devices. This method provides no man in the middle protection.
However, since "This method is typically used by headsets with very limited IO capabilities", it would probably not apply to the cellphones you are talking about, but I thought you should know :)
According to the offical Bluetooth Message Access Profile, i.e. the specific Bluetooth profile that deals with accessing SMS/MMS systems on phones via a remote device:
'The MCE device shall use the services of the MSE device only after successfully creating a secure connection. This includes exchanging of security initialization messages, creation of link keys, and enabling encryption'
From: https://developer.bluetooth.org/TechnologyOverview/Pages/MAP.aspx
There is also a link to the full spec there if you are interested.
This certtainly suggests that secure pairing is required, which I'd assume to involve the passkey. My experience is that once a device has been paired a connection can be made without repeating the pairing as long as that pairing is remembered by the devices (i.e. I've paired a device once and not had to do it again). As to simpler, non-keyed pairing mentioned by khellang above, I've not seen anything about this - if it is purely for devices like headsets then the security requirements may be lower due to their not likely wanting write access to a device?

ASP.NET - How to find out if the user is a mobile user?

I am trying to find out if a user viewing my site is a mobile user. I have used "HttpContext.Current.Request.Browser.IsMobileDevice " and found it pretty useless as it didn't not pick up on my usage when viewing the site on my phone.
Is there another way to find out if the user is a mobile user that works better?
I have looked at user agent and that just looks messy!
I should point out that this has nothing to do with CSS, I want to log if the user is a mobile user in a database table.
And yes, I know google analytics can do this already but unfortunately its not my decision!
Thanks
Check out
51degrees
It’s provided as a .NET open source class library that detects mobile
devices and browsers, enhancing the information available to .NET
programmers. Using 51Degrees.mobi Device Data, accurate screen sizes,
input methods, plus manufacturer and model information are all
available. Mobile handsets can optionally be redirected to content
designed for mobile devices. Smart phones, tablets and feature phones
are all supported.
As pointed out in the comments.
The detection and redirection part of the product offering is free.
The free trial is for their mobile optimzation products
See my comment on your question for a more thorough answer, but for a simple check to see if the user is a mobile user I would personally suggest
http://detectmobilebrowsers.com/
Try to test with this code....
string sUA = Request.UserAgent.Trim().ToLower();
uaString.InnerText = Request.UserAgent;
if (sUA.Contains("ipod") || sUA.Contains("iphone"))
isMobile = true;
if (sUA.Contains("android"))
isMobile = true;
if (sUA.Contains("opera mobi"))
isMobile = true;
if (sUA.Contains("windows phone os") && sUA.Contains("iemobile"))
isMobile = true;
if (sUA.Contains("fennec"))
isMobile = true;

Categories