如何使用Xamarin表单自动安装apk?

时间:2018-05-14 10:11:00

标签: android xamarin.forms apk android-install-apk

我想使用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);

            }

现在我正在获取此安装页面 enter image description here 但我应该开始自动安装应用程序。而不是从安装屏幕手动安装应用程序。

1 个答案:

答案 0 :(得分:1)

我检查了很多资源,我认为由于安全问题,无法进行自动安装。这些是我提到的链接

How can I auto install apk on android without market NOT system app

make auto install app in android easier?