如何解决Xamarin Android在复制apk文件时卡在黑屏上,但如果将USB连接到手机并从那里运行,则可以正常使用
这里是我启动应用程序时运行的代码:
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this,savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Button SearchRareButtonClick = FindViewById<Button>(Resource.Id.SearchRareButton);
ProgressBar SearchProgressBar = FindViewById<ProgressBar>(Resource.Id.SearchingProgressBar);
TextView DetectedRareLabel = FindViewById<TextView>(Resource.Id.DetectedRareBusLabel);
TextView StatusLabel = FindViewById<TextView>(Resource.Id.StatusLabel);
SearchRareButtonClick.Click += async (sender,args) =>
{
SearchRareButtonClick.Enabled = false;
if (await SendRareRequest() == true)
{
string RequestRecieved = "false";
while (RequestRecieved == "false")
{
RequestRecieved = await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/RequestRecieved.txt");
await Task.Delay(10);
}
var i = Int32.Parse(
await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/ProgressBarMaximum.txt"));
SearchProgressBar.Max = i;
string DoneState = "false";
while (DoneState == "false")
{
DoneState = await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/Done.txt");
StatusLabel.Text = await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/StatusLabel.txt");
try
{
SearchProgressBar.Progress =
Int32.Parse(
await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/Progress.txt"));
}
catch
{
}
await Task.Delay(10);
}
SearchProgressBar.Progress = 0;
DetectedRareLabel.Text = "Detected Rare Buses:\n" +
await DownloadStringFromFTP(
"ftp://ftpupload.net/htdocs/NextBus/RarePasser.txt");
}
else
{
SearchRareButtonClick.Text = "Server busy...";
await Task.Delay(2000);
SearchRareButtonClick.Text = "Search entire ttc for rare buses";
}
SearchRareButtonClick.Enabled = true;
};
}
public override void OnRequestPermissionsResult(int requestCode,string[] permissions,[GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode,permissions,grantResults);
base.OnRequestPermissionsResult(requestCode,grantResults);
}
private async Task DownloadFromFTP(string link,string filename)
{
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential(FTPUsername,FTPPassword);
client.DownloadFileAsync(new Uri(link),filename);
while (client.IsBusy)
{
await Task.Delay(10);
}
}
}
private async Task UploadToFTP(string link,FTPPassword);
client.UploadFileAsync(new Uri(link),filename);
while (client.IsBusy)
{
await Task.Delay(10);
}
}
}
private async Task<string> DownloadStringFromFTP(string link)
{
string Return = "";
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential(FTPUsername,FTPPassword);
Return = client.DownloadString(new Uri(link));
while (client.IsBusy)
{
await Task.Delay(10);
}
}
return Return;
}
private async Task UploadStringToFTP(string link,string content)
{
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential(FTPUsername,FTPPassword);
client.UploadString(new Uri(link),content);
while (client.IsBusy)
{
await Task.Delay(10);
}
}
}
private async Task<bool> SendRareRequest()
{
bool Return = false;
string State = await DownloadStringFromFTP("ftp://ftpupload.net/htdocs/NextBus/StartProcess.txt");
if (State == "false")
{
await UploadStringToFTP("ftp://ftpupload.net/htdocs/NextBus/StartProcess.txt","true");
Return = true;
}
else if (State == "true")
{
Return = false;
}
return Return;
}
当我复制通过Visual Studio分发的apk文件时,它有时会立即崩溃,有时会永远显示空白屏幕,但是当我将手机连接到USB并通过USB调试进行操作时,它无需任何操作问题,是否需要更改任何设置才能使其正常工作?Visual Studio是否存在问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。