Weird issue with app update using apk install code

1

App gets successfully updated but the following issue are occurring based on different code usage

  1. After apk install, "app install success" screen of app installer not showing up
  2. If I use debug apks to test above case, for one particular code, as always install succeeds, "app install success" screen appears, clicking open button successfully opens the app. But if I use signed release apks to test the same code, clicking open button in "install success" won't open the app. The app can be opened fine if opened from the launcher.

I have tried different code from the many stackoverflow question and blogs. I even tried one google sample code from here, https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/content/InstallApk.java but nothing solves the issue. I tried these code using debug apks and release apks

private static Uri uriFromFile(Context context, File file) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file);
    } else {
        return Uri.fromFile(file);
    }
}

case 1: ("app install success" screen of app installer not showing up)

public void installNewFile() {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
          .
          .
    startActivityForResult(intent, 999);
}

case 2: (For Release apks, clicking open in "app install success" screen not opening the app. But for debug apks, app is opening fine)

public void installNewFile() {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uriFromFile(context, new File(path)), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
    intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,
        context.getApplicationInfo().packageName);

    try {
        startActivity(intent);
        finish();
    }catch (ActivityNotFoundException e){
        Toast.makeText(context, "Application installer not found!", Toast.LENGTH_SHORT).show();
        Log.e(TAG, "installNewFile: ", e);
    }
}
Manifest:
<application
    android:name=".MposApp"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <uses-library android:name="org.apache.http.legacy" android:required="false"/>

        <provider
            android:authorities="com.example.appname.fileprovider"
            android:name=".autoupdateutil.ApkProvider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

        <activity
            android:name=".activity.base.SplashActivity"
            android:configChanges="orientation|screenSize"
            android:resizeableActivity="false"
            android:exported="true"
            tools:targetApi="n">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="ANDROID.INTENT.CATEGORY.DEFAULT" />

                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
            </intent-filter>

            <meta-data
                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/usb_device_filter" />
            <meta-data
                android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                android:resource="@xml/usb_device_filter" />

            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
            </intent-filter>
        </activity>
.
.
.
.

Expected case is the app should be able to open from "app install success screen"

Clicking the open button in "install success" screen, leaves the following system log

"I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.example.appname cmp=com.example.appname/.activity.base.SplashActivity} from uid 10021 pid 31899"

But app is not opened

The logs in the application class and spashActivity onCreate() screens are not appearing in this case

java
android
android-install-apk
asked on Stack Overflow Aug 26, 2019 by Panneerdas P • edited Aug 27, 2019 by Fábio Nascimento

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0