Java Code Examples for android.content.Intent#ACTION_PACKAGE_REPLACED

The following examples show how to use android.content.Intent#ACTION_PACKAGE_REPLACED . These examples are extracted from open source projects. 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
static private ChangelogTask getEventTask(Context context, String packageName, String action) {
    App app = YalpStoreApplication.installedPackages.get(packageName);
    if (null == app) {
        app = new App();
        app.setPackageInfo(new PackageInfo());
        app.getPackageInfo().packageName = packageName;
    }
    ChangelogTask task = new ChangelogTask();
    task.setContext(context);
    task.setApp(app);
    switch (action) {
        case ACTION_PACKAGE_INSTALLATION_FAILED:
            task.setEventType(Event.TYPE.INSTALLATION, false);
            break;
        case Intent.ACTION_PACKAGE_FULLY_REMOVED:
        case Intent.ACTION_PACKAGE_REMOVED:
            task.setEventType(Event.TYPE.REMOVAL, true);
            break;
        case Intent.ACTION_PACKAGE_INSTALL:
        case Intent.ACTION_PACKAGE_ADDED:
        case Intent.ACTION_PACKAGE_REPLACED:
            task.setEventType(app.getInstalledVersionCode() > 0 ? Event.TYPE.UPDATE : Event.TYPE.INSTALLATION, true);
            break;
    }
    return task;
}
 
Example 2
@Override protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();
    final String packageName = intent.getData()
        .getEncodedSchemeSpecificPart();

    if (!TextUtils.equals(action, Intent.ACTION_PACKAGE_REPLACED) && intent.getBooleanExtra(
        Intent.EXTRA_REPLACING, false)) {
      // do nothing if its a replacement ongoing. we are only interested in
      // already replaced apps
      return;
    }

    switch (action) {
      case Intent.ACTION_PACKAGE_ADDED:
        onPackageAdded(packageName);
        break;
      case Intent.ACTION_PACKAGE_REPLACED:
        onPackageReplaced(packageName);
        break;
      case Intent.ACTION_PACKAGE_REMOVED:
        onPackageRemoved(packageName);
        break;
    }
  }
}
 
Example 3
Source Project: android_9.0.0_r45   File: Vpn.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final Uri data = intent.getData();
    final String packageName = data == null ? null : data.getSchemeSpecificPart();
    if (packageName == null) {
        return;
    }

    synchronized (Vpn.this) {
        // Avoid race where always-on package has been unset
        if (!packageName.equals(getAlwaysOnPackage())) {
            return;
        }

        final String action = intent.getAction();
        Log.i(TAG, "Received broadcast " + action + " for always-on VPN package "
                + packageName + " in user " + mUserHandle);

        switch(action) {
            case Intent.ACTION_PACKAGE_REPLACED:
                // Start vpn after app upgrade
                startAlwaysOnVpn();
                break;
            case Intent.ACTION_PACKAGE_REMOVED:
                final boolean isPackageRemoved = !intent.getBooleanExtra(
                        Intent.EXTRA_REPLACING, false);
                if (isPackageRemoved) {
                    setAlwaysOnPackage(null, false);
                }
                break;
        }
    }
}
 
Example 4
Source Project: DevUtils   File: AppStateReceiver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceive(Context context, Intent intent) {
        try {
            String action = intent.getAction();
            // 打印当前触发的广播
            LogPrintUtils.dTag(TAG, "onReceive Action: " + action);
            // 被操作应用包名
            String packageName = null;
            Uri uri = intent.getData();
            if (uri != null) {
//                packageName = uri.toString();
                packageName = uri.getEncodedSchemeSpecificPart();
            }
            // 判断类型
            switch (action) {
                case Intent.ACTION_PACKAGE_ADDED: // 应用安装
                    if (sListener != null) {
                        sListener.onAdded(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REPLACED: // 应用更新
                    if (sListener != null) {
                        sListener.onReplaced(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REMOVED: // 应用卸载
                    if (sListener != null) {
                        sListener.onRemoved(packageName);
                    }
                    break;
            }
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "onReceive");
        }
    }
 
Example 5
@Override
public void onReceive(Context context, final Intent intent) {
    String status = null;
    ApplicationStatus applicationState;
    switch (intent.getAction()) {
        case Intent.ACTION_PACKAGE_ADDED:
            status = "added";
            break;
        case Intent.ACTION_PACKAGE_REMOVED:
            status = "removed";
            break;
        case Intent.ACTION_PACKAGE_REPLACED:
            status = "upgraded";
            break;
        case Intent.ACTION_PACKAGE_DATA_CLEARED:
            status = "dataCleared";
            break;
        default:
            Log.i(TAG, "Invalid intent received");
    }
    if (status != null) {
        String packageName = intent.getData().getEncodedSchemeSpecificPart();
        applicationState = new ApplicationStatus();
        applicationState.setState(status);
        applicationState.setPackageName(packageName);
        try {
            String appState = CommonUtils.toJSON(applicationState);
            publishEvent(appState, Constants.EventListeners.APPLICATION_STATE);
            if (Constants.DEBUG_MODE_ENABLED) {
                Log.d(TAG, appState);
            }
        } catch (AndroidAgentException e) {
            Log.e(TAG, "Could not convert to JSON");
        }
    }
}