com.google.android.play.core.install.model.InstallStatus Java Examples

The following examples show how to use com.google.android.play.core.install.model.InstallStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateManager.java    From InAppUpdater with MIT License 6 votes vote down vote up
@Override
public void onStateUpdate(InstallState installState) {
    if (installState.installStatus() == InstallStatus.DOWNLOADING) {
        long bytesDownloaded = installState.bytesDownloaded();
        long totalBytesToDownload = installState.totalBytesToDownload();
        if (flexibleUpdateDownloadListener != null) {
            flexibleUpdateDownloadListener.onDownloadProgress(bytesDownloaded, totalBytesToDownload);
        }
    }
    if (installState.installStatus() == InstallStatus.DOWNLOADED) {
        // After the update is downloaded, show a notification
        // and request user confirmation to restart the app.
        Log.d(TAG, "An update has been downloaded");
        popupSnackbarForCompleteUpdate();
    }
}
 
Example #2
Source File: CommcareFlexibleAppUpdateManager.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void fetchAppUpdateInfo() {
    mAppUpdateManager.getAppUpdateInfo()
            .addOnSuccessListener(info -> {
                mAppUpdateInfo = info;
                mUpdateAvailability = info.updateAvailability();
                mInstallStatus = info.installStatus();
                publishStatus();
            })
            .addOnFailureListener(exception -> {
                mAppUpdateInfo = null;
                mUpdateAvailability = UpdateAvailability.UNKNOWN;
                mInstallStatus = InstallStatus.UNKNOWN;
                Logger.log(TAG, "fetchAppUpdateInfo|failed with : " + exception.getMessage());
                publishStatus();
            });
}
 
Example #3
Source File: CommcareFlexibleAppUpdateManager.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Gets {@link AppUpdateState} using {@link #mUpdateAvailability} and {@link #mInstallStatus}
 */
private AppUpdateState getAppUpdateState() {
    AppUpdateState state = AppUpdateState.UNAVAILABLE;
    switch (mInstallStatus) {
        case InstallStatus.PENDING:
        case InstallStatus.DOWNLOADING:
            state = AppUpdateState.DOWNLOADING;
            break;
        case InstallStatus.DOWNLOADED:
            state = AppUpdateState.DOWNLOADED;
            break;
        case InstallStatus.FAILED:
            state = AppUpdateState.FAILED;
            break;
    }
    if (state == AppUpdateState.UNAVAILABLE && mUpdateAvailability == UpdateAvailability.UPDATE_AVAILABLE) {
        state = AppUpdateState.AVAILABLE;
    }
    return state;
}
 
Example #4
Source File: UpdateManager.java    From InAppUpdater with MIT License 5 votes vote down vote up
private void continueUpdateForFlexible() {
    instance.appUpdateManager
            .getAppUpdateInfo()
            .addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
                @Override
                public void onSuccess(AppUpdateInfo appUpdateInfo) {
                    // If the update is downloaded but not installed,
                    // notify the user to complete the update.
                    if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
                        Log.d(TAG, "An update has been downloaded");
                        instance.popupSnackbarForCompleteUpdate();
                    }
                }
            });
}
 
Example #5
Source File: InAppUpdateManager.java    From android-inapp-update with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateUpdate(InstallState installState) {
    inAppUpdateStatus.setInstallState(installState);

    reportStatus();

    // Show module progress, log state, or install the update.
    if (installState.installStatus() == InstallStatus.DOWNLOADED) {
        // After the update is downloaded, show a notification
        // and request user confirmation to restart the app.
        popupSnackbarForUserConfirmation();
    }
}
 
Example #6
Source File: InAppUpdateManager.java    From android-inapp-update with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the update is not stalled during 'onResume()'.
 * However, you should execute this check at all app entry points.
 */
private void checkNewAppVersionState() {

    appUpdateManager
            .getAppUpdateInfo()
            .addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
                @Override
                public void onSuccess(AppUpdateInfo appUpdateInfo) {

                    inAppUpdateStatus.setAppUpdateInfo(appUpdateInfo);

                    //FLEXIBLE:
                    // If the update is downloaded but not installed,
                    // notify the user to complete the update.
                    if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
                        popupSnackbarForUserConfirmation();
                        reportStatus();
                        Log.d(LOG_TAG, "checkNewAppVersionState(): resuming flexible update. Code: " + appUpdateInfo.updateAvailability());
                    }

                    //IMMEDIATE:
                    if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                        // If an in-app update is already running, resume the update.
                        startAppUpdateImmediate(appUpdateInfo);

                        Log.d(LOG_TAG, "checkNewAppVersionState(): resuming immediate update. Code: " + appUpdateInfo.updateAvailability());

                    }
                }
            });

}
 
Example #7
Source File: MainActivity.java    From VoIpUSSD with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateUpdate(InstallState installState) {
    if (installState.installStatus() == InstallStatus.DOWNLOADED) {
        showMessage("Has been Downloaded!!!");
        notifyUser();
    }
}
 
Example #8
Source File: MainActivity.java    From VoIpUSSD with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
        @Override
        public void onSuccess(AppUpdateInfo result) {
            if (result.installStatus() == InstallStatus.DOWNLOADED) {
                notifyUser();
            }
        }
    });
}
 
Example #9
Source File: CommcareFlexibleAppUpdateManager.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startUpdate(Activity activity) {
    try {
        boolean success = mAppUpdateManager.startUpdateFlowForResult(
                mAppUpdateInfo, AppUpdateType.FLEXIBLE, activity, IN_APP_UPDATE_REQUEST_CODE);
        if (!success) {
            Logger.log(TAG, "startUpdate|requested update cannot be started");
        }
    } catch (IntentSender.SendIntentException exception) {
        mInstallStatus = InstallStatus.FAILED;
        mInstallErrorCode = InstallErrorCode.ERROR_INTERNAL_ERROR;
        Logger.log(TAG, "startUpdate|failed with : " + exception.getMessage());
        publishStatus();
    }
}
 
Example #10
Source File: CommcareFlexibleAppUpdateManager.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Integer getProgress() {
    if (mInstallStatus != InstallStatus.DOWNLOADING) {
        return null;
    }
    return percentageDownloaded;
}
 
Example #11
Source File: CommcareFlexibleAppUpdateManager.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateUpdate(InstallState state) {
    Logger.log(TAG, "Install state updated with install status: " + state.installStatus()
            + ", and error code: " + state.installErrorCode());
    mInstallErrorCode = state.installErrorCode();
    if (state.installStatus() == InstallStatus.DOWNLOADING) {
        // TODO: Should be keep on publishing status for showing download percentage.
        // From https://stackoverflow.com/a/10415638/6671572
        percentageDownloaded = (int) (state.bytesDownloaded() * 100.0 / state.totalBytesToDownload() + 0.5) ;
    }
    if (mInstallStatus != state.installStatus()) {
        mInstallStatus = state.installStatus();
        publishStatus();
    }
}
 
Example #12
Source File: InAppUpdateStatus.java    From android-inapp-update with Apache License 2.0 4 votes vote down vote up
public boolean isDownloading() {
    if (installState != null)
        return installState.installStatus() == InstallStatus.DOWNLOADING;

    return false;
}
 
Example #13
Source File: InAppUpdateStatus.java    From android-inapp-update with Apache License 2.0 4 votes vote down vote up
public boolean isDownloaded() {
    if (installState != null)
        return installState.installStatus() == InstallStatus.DOWNLOADED;

    return false;
}
 
Example #14
Source File: InAppUpdateStatus.java    From android-inapp-update with Apache License 2.0 4 votes vote down vote up
public boolean isFailed() {
    if (installState != null)
        return installState.installStatus() == InstallStatus.FAILED;

    return false;
}