0

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 enter image description here But I should start installing the app automatically. Instead of manually installing the app from install screen.

Ziauz
  • 773
  • 4
  • 22
Judson Abraham
  • 316
  • 2
  • 11
  • 37
  • 1
    You can't install an app without the user permission. It's a security principle of Android OS – Diego Rafael Souza May 14 '18 at 11:31
  • 1
    Can u provide me any documentation or proof for that. That will be really use full for me @DiegoRafaelSouza and write that in answer section instead of comment section. – Judson Abraham May 14 '18 at 11:40
  • 1
    [This answer provides the perfect summary of your situation](https://stackoverflow.com/a/4604922/8093394). [This one](https://stackoverflow.com/a/5805299/8093394) suggests a workaround to do that, but I haven't tested such thing at all. I hope it helps you. – Diego Rafael Souza May 14 '18 at 15:54
  • Thanks for your suggestions @DiegoRafaelSouza but that didn't work for me. – Judson Abraham May 15 '18 at 04:15

1 Answers1

1

I have checked lots of resources and I think that auto install is not possible because of security issues. These are the links which I referred

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

make auto install app in android easier?

Judson Abraham
  • 316
  • 2
  • 11
  • 37