= Build.VERSION_CODES.N){Uri fileUri = FileProvider.getUriForFile(getBaseContext(),getApplicationContext().getPackageName() + ".provider", file);Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, getApplicationInfo().packageName);startActivityForResult(intent, 1);}else ...The result..." />

Android application self-update cancelled for unknown reason

My Android app contains a code that check for update every time the app is executed. If a new version is available, the APK file is downloaded in the background (using AsyncTask) and once it's stored into getExternalFilesDir(null) directory, the application attempt to install its new version.

The code related to the installation is as follows:

Manifest:


android:name="android.support.v4.content.FileProvider"

android:authorities="${applicationId}.provider"

android:exported="false"

android:grantUriPermissions="true">


android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/paths"/>



paths.xml:









Java:

File file = new File(

context.getExternalFilesDir(null),

resources.getString(R.string.app_name) + ".apk");

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)

{

Uri fileUri = FileProvider.getUriForFile(

getBaseContext(),

getApplicationContext().getPackageName() + ".provider", file);

Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);

intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");

intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);

intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);

intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, getApplicationInfo().packageName);

startActivityForResult(intent, 1);

}

else ...

The result...

Read More »

By: StackOverFlow - Tuesday, 6 November

Related Posts

  • Older News
  • StackOverFlowError in android while uploading to storage StackOverFlow (2 days ago) - FATAL EXCEPTION: mainProcess: com.appmaster.akash.messageplus, PID: 10668java.lang.StackOverflowError: stack size 8MBat java.lang.reflect.Method.invoke(Native Method)at com.google.android.gms.internal.zzeas.zzbu(Unknown Source:128)at com.google.android.gms.internal.zzear.zzbq(Unknown Source:263)at com.google.android.gms.internal.zzear.zzbt(Unknown Source:0)at com.google.android.gms.internal.zzeas.zzbu(Unknown Source:132)at com.google.android.gms.internal.zzear.zzbq(Unknown Source:263)at com.google.android.gms.internal.zzear.zzbt(Unknown Source:0)at com.google.android.gms.internal.zzeas.zzbu(Unknown Source:132)at com.google.android.gms.internal.zzear.zzbq(Unknown Source:263)at com.google.android.gms.internal.zzear.zzbt(Unknown Source:0)at com.google.android.gms.internal.zzeas.zzbu(Unknown...