-1

I've been struggling to get my application to update from a direct url, i want to download a apk and then prompt to user to install the apk. How can I do this?

Thanks.

EDIT:

Intent intent = new Intent(Intent.ActionView);
            intent.SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/download/" + "WhatsApp Messenger_v2.17.395_apkpure.com.apk")), "application/vnd.android.package-archive");
            intent.AddFlags(ActivityFlags.GrantReadUriPermission);
            intent.SetFlags(ActivityFlags.NoHistory);
            intent.SetFlags(ActivityFlags.ClearWhenTaskReset);


            Forms.Context.StartActivity(Intent.CreateChooser(intent, "Open APK"));

With the code above , opens the app and asks to install with android 4.4, but in my phone android 7.0 doesnt work, gives this alert:"There was a problem parsing the package".

Phill
  • 407
  • 1
  • 8
  • 30

1 Answers1

0

Then how can i open the apk after is downloaded?

You could use following code :

Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/download/" + "app.apk")), "application/vnd.android.package-archive");
intent.SetFlags(ActivityFlags.NewTask);
StartActivity(intent);

For more information, you could refer to : Android: install .apk programmatically

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • Gives a exception: Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown – Phill Nov 10 '17 at 10:10
  • I edited my post with a code that works in android 4.4 , but in android 7.0 doesnt work. – Phill Nov 10 '17 at 10:50
  • Is not a error, is a alert, is this only: "There was a problem parsing the package"" – Phill Nov 10 '17 at 16:07
  • @Phill, you could refer to : http://www.technicalnotes.org/fix-parse-error-in-android-there-is-a-problem-parsing-the-package/ – Grace Feng Nov 12 '17 at 13:37