我想使用Xamarin Forms自动安装apk。我可以使用我的代码获取apk的安装屏幕,但这使我手动安装应用程序。这是我的代码
public void ApkInstall()
{
try
{
var filename = "XYZ.apk";
System.Diagnostics.Debug.WriteLine("The file name is" + filename);
var path = "Install apk/";
var destination = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.ToString(), path + filename);
System.Diagnostics.Debug.WriteLine("The destination is" + destination);
//Android.Net.Uri uri = Android.Net.Uri.("file://" + destination);
Intent install = new Intent(Intent.ActionInstallPackage);
//install.PutExtra(Intent.ExtraNotUnknownSource, true);
//install.AddFlags(ActivityFlags.ClearTask);
install.SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.ToString() + "/Install apk/" + filename)), "application/vnd.android.package-archive");
install.SetFlags(ActivityFlags.ClearTask|ActivityFlags.NewTask);
install.AddFlags(ActivityFlags.GrantReadUriPermission);
Forms.Context.StartActivity(install);
//Forms.Context.UnregisterReceiver(this);
}
答案 0 :(得分:1)
我检查了很多资源,我认为由于安全问题,无法进行自动安装。这些是我提到的链接
How can I auto install apk on android without market NOT system app