how to auto install apk using Xamarin forms

judsonabrahamjudsonabraham USMember ✭✭✭
edited May 2018 in Xamarin.Forms

Hi I want to auto install apk using Xamarin forms. I'm able to get the install screen of the apk using my code but that makes me install the app manually. This is my code
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);

            }

Right now I'm getting this installation page
https://onlinesupport.miradore.com/hc/en-us/article_attachments/201571352/24-06-2015_deploy_googleplay_app_client_3.png
But I should start installing the app automatically .Instead of manually installing the app from install screen. If it's not possible please provide me a proof or a documentation regarding that please.

Best Answers

Answers

Sign In or Register to comment.