简体   繁体   English

ShareLinkTask,检查用户是否已连接到网络

[英]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. 我想在Windows Phone应用程序中使用ShareLinkTask,以使用户可以共享链接。

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. 您可以使用Account类确定触发任务之前是否设置了任何用户帐户。

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. 请注意,这样做需要ID_CAP_CONTACTS和ID_CAP_APPOINTMENTS,这对您的用户可能看起来很奇怪,并且看到这是一个极端的情况(很少有没有使用任何帐户的电话),可能不值得额外的代码/功能要求。

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. 您在模拟器上看到的行为是因为您没有使用Microsoft帐户登录到手机。 As such there are no social networks associated that can be used to share the link. 因此,没有关联的社交网络可用于共享链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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