简体   繁体   中英

ShareLinkTask, check if a user has connected to a network

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM