【发布时间】:2020-03-17 20:27:36
【问题描述】:
我正在尝试从我的 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 "";
}
}
你有什么想法吗?
谢谢,杰彭
【问题讨论】:
-
我没有使用 Tizen 可穿戴设备,但是用
async替换您的任务等待/结果以防止死锁。
标签: android xamarin tizen-wearable-sdk android-wear-2.0