如果您可以提供帮助,请,我正在尝试将APK文件从服务器移动到外部存储。
我面对这个问题:Android.OS.FileUriExposedException:'file:///storage/emulated/0/Download/MyAppApks/add.txt通过Intent.getData()暴露在应用程序之外'
var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
var apkDirectory = new Java.IO.File(dir, "MyAppApks");
apkDirectory.Mkdirs();
var client = new HttpClient();
var apkUrl = "http://**.**.**.**:2030/com.companyname.app1.apk";
var response = await client.GetAsync(apkUrl);
var apkFile = new Java.IO.File(apkDirectory, "com.companyname.app1.apk");
using (var stream = new FileStream(apkFile.AbsolutePath, FileMode.Create, FileAccess.Write))
{
await response.Content.CopyToAsync(stream);
}
var intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Android.Net.Uri.FromFile(apkFile), "application/vnd.android.package-archive");
intent.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);
1条答案
按热度按时间6ie5vjzr1#
试试这个: