Skip to content Skip to sidebar Skip to footer

Install Apk Programmatically - Return Value

In my app, I am calling a javascript interface from my activity. In the webview associated with this interface, I am asking the user to download and install an APK. I am using a 's

Solution 1:

We developed an app market and faced the same problem. Our solution was to use the packet manager as you propose.

I looked into some intent-filters as there seem to be some intents around the installation process. But we were not able to get it running. The packet-manager solution works fine tho as you can check the app version which is important on app-updates.

Solution 2:

You can check the firstInstallTime/lastUpdateTime and compare with your request time to PackageInstaller for install your package, see example below:

try {

    PackageInfoinstalledPackageInfo= getPackageManager()
            .getPackageInfo(installedPackageName, PackageManager.GET_ACTIVITIES);
    longfirstInstallTime= installedPackageInfo.firstInstallTime;
    longlastUpdateTime= installedPackageInfo.lastUpdateTime;

    // installationRequestTime is the time which you request for the PackageInstaller to install your package. This time should be got from System.currentTimeMillis()return firstInstallTime > installationRequestTime || lastUpdateTime > installationRequestTime;
} catch (PackageManager.NameNotFoundException e) {
    // First time installation and user choose to not install the appreturnfalse;
}

That solution isn't pretty, but unfortunately PackageInstaller don't provide a clear resultCode to us.

Post a Comment for "Install Apk Programmatically - Return Value"