In App Upgrade for Android Oreo (API Version 26) - android

My App is distributed outside of Play Store and it is upgraded within the App when there is a new version available. I am using the below code to start the install (after the file was downloaded using DownloadManager)
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/app.apk";
For Android N (24):
Uri contentUri = FileProvider.getUriForFile(ctxt, BuildConfig.APPLICATION_ID + ".provider", new File(destination));
Intent openFileIntent = new Intent(Intent.ACTION_VIEW);
openFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
openFileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
openFileIntent.setData(contentUri);
startActivity(openFileIntent);
For Android 23 and below:
final Uri uri = Uri.parse("file://" + destination);
Intent install = new Intent(Intent.ACTION_VIEW);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setDataAndType(uri,"application/vnd.android.package-archive");
startActivity(install);
When I use the same code for "Android N", it is not showing the system install activity in Android Oreo. Anyone who has solved this problem?

Related

Problem apk Installation in android devices programmatically

private void installNewApk(String outputFile) {
Uri uri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(outputFile + "app-demo-debug.apk"));
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.putExtra(Intent.ACTION_INSTALL_PACKAGE, true);
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(install);
}
My apk is not corrupted file because manually my apk install but programmatically not install.
Unknown Source already allow
please provide the answer

How to install Apk from app using Xamarin android

I am trying to update my app programmatically.
I am able to download the new version of the app apk.
But when the installation code runs nothing happens except an activity that is opened and then closed returning to my app
The installation code is
Java.IO.File apkFile = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/download/" + "com.tri.GOT.apk");
var context = Android.App.Application.Context;
var downloadUri = FileProvider.GetUriForFile(context, "com.tri.GOT.fileprovider", apkFile);
Intent install = new Intent(Intent.ActionView);
install.AddFlags(ActivityFlags.NewTask);
install.AddFlags(ActivityFlags.GrantReadUriPermission);
install.AddFlags(ActivityFlags.GrantWriteUriPermission);
install.AddFlags(ActivityFlags.GrantPersistableUriPermission);
install.SetDataAndType(downloadUri, "application/vnd.android.package-archive");
context.StartActivity(install);

Installation dialog not shown in oreo when done programatically if device is not rooted

I am trying to update app after showing the alert dialog in my app. It is working fine below Android Oreo. Here is what I have tried till now
String ANDROID_PACKAGE = "application/vnd.android.package-archive";
File update_apk = new File(context.getFilesDir(), intent.getStringExtra("update_file"));
Intent notificationIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
notificationIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
notificationIntent.setDataAndType(
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", update_apk),
ANDROID_PACKAGE);
} else {
notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setDataAndType(
Uri.parse("file://" + update_apk.getAbsolutePath()),
ANDROID_PACKAGE);
}
startActivity(notificationIntent);
How to show this app update dialog in the devices which are not rooted. Any help would be appreciated. Thanks in aadvance.
Check below permission in your manifest.xml file.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Also check your file provider for Intent.VIEW_ACTION.
More reference check this page Android install apk with Intent.VIEW_ACTION not working with File provider
enjoy code.

How to correct update Android .apk?

Intent openIntent;
File file = new File(mApkPath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String auth = mContext.getPackageName() + ".file.provider";
Uri apkUri = FileProvider.getUriForFile(mContext, auth, file);
openIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
openIntent.setData(apkUri);
openIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
openIntent = new Intent(Intent.ACTION_VIEW);
openIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
openIntent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
return openIntent;
I found this way can open an Activity which is mean "Install Success" in low SDK version Android device, but in hight SDK version, when install finished, the app will like crash, even if the new .apk was installed.
Have any way to open the activity which is mean "Install Success", so that let user can choose install 'Finished' or 'Open'?
By the way, I got resultCode == RESULT_CANCELED, actually, new .apk was installed. And I notice PackageInstaller can user update apk, but how to use it? I read ApiDemos but got result == PackageInstaller.STATUS_PENDING_USER_ACTION by int result = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE), but .apk was Installed and no any 'Finished' or 'Open' button.
Thanks!

Package installer doesn't ask to click on "Done" or "Open" after updating app programmatically

My app has Auto-Update feature. I install apk file using this code:
Uri uri;
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file);
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData(uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
uri = Uri.fromFile(file);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
The problem is that in api 24 or higher Android package installer doesn't ask to click on "Done" or "Open" after updating completed and dialog will be closed without any questions or any messages.
I need package installer ask what to do like
.

Categories

Resources