我正在尝试从我的android手表调用网站,但是线程退出(线程0x5已退出,代码0(0x0)),但没有结果。我添加了权限“ Internet”和“ Network_state”,但不会更改结果。在我的代码下面(在Tizen和纯Xamarin中完成):
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
textView = FindViewById<TextView>(Resource.Id.text);
Button mybtn = FindViewById<Button>(Resource.Id.btnCal);
SetAmbientEnabled();
try
{
mybtn.Click += delegate
{
Task<string> callTask = calculateRoute();
callTask.Wait();
string astr = callTask.Result;
};
}
catch (Exception ex)
{
string tt = ex.ToString();
}
}
private async Task<string> calculateRoute()
{
HttpClient client;
try
{
String RestUrl = "https://www.google.com";
var uri = new Uri(string.Format(RestUrl, string.Empty));
client = new System.Net.Http.HttpClient();
var response = await client.GetAsync(uri);
var content = await response.Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
string tt = ex.ToString();
return "";
}
}
你有什么想法吗?
谢谢,吉彭
经过大量研究后,我找到了解决方案,这要归功于:https://github.com/Samsung/Tizen-CSharp-Samples/tree/master/Wearable