Example usage for android.content Intent ACTION_PACKAGE_REPLACED

List of usage examples for android.content Intent ACTION_PACKAGE_REPLACED

Introduction

In this page you can find the example usage for android.content Intent ACTION_PACKAGE_REPLACED.

Prototype

String ACTION_PACKAGE_REPLACED

To view the source code for android.content Intent ACTION_PACKAGE_REPLACED.

Click Source Link

Document

Broadcast Action: A new version of an application package has been installed, replacing an existing version that was previously installed.

Usage

From source file:com.google.android.apps.dashclock.ExtensionPackageChangeReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    ExtensionManager extensionManager = ExtensionManager.getInstance(context);
    if (extensionManager.cleanupExtensions()) {
        LOGD(TAG, "Extension cleanup performed and action taken.");

        Intent widgetUpdateIntent = new Intent(context, DashClockService.class);
        widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS);
        startWakefulService(context, widgetUpdateIntent);
    }/*w ww  .j av a  2s  .c  o  m*/

    // If this is a replacement or change in the package, update all active extensions from
    // this package.
    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_CHANGED.equals(action) || Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
        String packageName = intent.getData().getSchemeSpecificPart();
        if (TextUtils.isEmpty(packageName)) {
            return;
        }

        Set<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames();
        for (ComponentName cn : activeExtensions) {
            if (packageName.equals(cn.getPackageName())) {
                LOGD(TAG, "Package for extension " + cn + " changed; asking it for an update.");
                Intent extensionUpdateIntent = new Intent(context, DashClockService.class);
                extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS);
                // TODO: UPDATE_REASON_PACKAGE_CHANGED
                extensionUpdateIntent.putExtra(DashClockService.EXTRA_COMPONENT_NAME,
                        cn.flattenToShortString());
                startWakefulService(context, extensionUpdateIntent);
            }
        }
    }
}

From source file:org.wso2.iot.agent.events.listeners.ApplicationStateListener.java

@Override
public void startListening() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    intentFilter.addDataScheme("package");
    EventRegistry.context.registerReceiver(this, intentFilter);
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.SessionNotesFragment.java

@Override
public void onResume() {
    super.onResume();

    getLoaderManager().restartLoader(0, null, this);

    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:org.wso2.iot.agent.events.listeners.ApplicationStateListener.java

@Override
public void onReceive(Context context, final Intent intent) {
    String status = null;/*from  www.j av  a  2  s . c  o  m*/
    ApplicationStatus applicationState;
    this.context = context;
    switch (intent.getAction()) {
    case Intent.ACTION_PACKAGE_ADDED:
        status = "added";
        applyEnforcement(intent.getData().getEncodedSchemeSpecificPart());
        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");
        }
        if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())
                && Constants.AGENT_PACKAGE.equals(packageName)) {
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction(Constants.AGENT_UPDATED_BROADCAST_ACTION);
            context.sendBroadcast(broadcastIntent);
        }
    }
}

From source file:com.lullabot.android.apps.iosched.ui.SessionDetailFragment.java

@Override
public void onResume() {
    super.onResume();

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:tw.idv.gasolin.pycontw2012.ui.SessionDetailFragment.java

@Override
public void onResume() {
    super.onResume();

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
}

From source file:com.goliathonline.android.kegbot.ui.DrinkDetailFragment.java

@Override
public void onResume() {
    super.onResume();
    updateNotesTab();/*from w  w w . j a  v  a  2 s. c  o  m*/

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:com.google.android.apps.iosched2.ui.SessionDetailFragment.java

@Override
public void onResume() {
    super.onResume();
    SetupHelper.loadCurrentSetup(getActivity());

    updateNotesTab();// w w  w .  j  av a  2s .c o m

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (mDrawerLayout != null) {
        final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        /**//from  w w w .  ja v  a2  s.c o  m
         * xinsi
         *
         * Intent.ACTION_PACKAGE_REMOVED:
         * Broadcast Action: An existing application package has been removed from the device.
         *
         * Intent.ACTION_PACKAGE_REPLACED:
         * Broadcast Action: A new version of an application package has been installed,
         * replacing an existing version that was previously installed.
         */
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addDataScheme("package");
        registerReceiver(mPackageReceiver, filter);

        new CategoriesUpdater().execute();
    }
    final Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(EXTRA_SHOW_MENU)) {
            if (intent.getBooleanExtra(EXTRA_SHOW_MENU, false)) {
                // Intent explicitly set to show menu.
                showMenuIcon();
            }
        } else if (isTopLevelTile(intent)) {
            showMenuIcon();
        }
    }
}

From source file:com.anysoftkeyboard.addons.AddOnsFactory.java

private boolean isEventRequiresCacheRefresh(Intent eventIntent) throws NameNotFoundException {
    String action = eventIntent.getAction();
    String packageNameSchemePart = eventIntent.getData().getSchemeSpecificPart();
    if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
        //will reset only if the new package has my addons
        boolean hasAddon = isPackageContainAnAddon(packageNameSchemePart);
        if (hasAddon) {
            Logger.d(mTag, "It seems that an addon exists in a newly installed package " + packageNameSchemePart
                    + ". I need to reload stuff.");
            return true;
        }/*from  w  w  w .j a va2s.c  o m*/
    } else if (Intent.ACTION_PACKAGE_REPLACED.equals(action) || Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
        //If I'm managing OR it contains an addon (could be new feature in the package), I want to reset.
        boolean isPackagedManaged = isPackageManaged(packageNameSchemePart);
        if (isPackagedManaged) {
            Logger.d(mTag, "It seems that an addon I use (in package " + packageNameSchemePart
                    + ") has been changed. I need to reload stuff.");
            return true;
        } else {
            boolean hasAddon = isPackageContainAnAddon(packageNameSchemePart);
            if (hasAddon) {
                Logger.d(mTag, "It seems that an addon exists in an updated package " + packageNameSchemePart
                        + ". I need to reload stuff.");
                return true;
            }
        }
    } else //removed
    {
        //so only if I manage this package, I want to reset
        boolean isPackagedManaged = isPackageManaged(packageNameSchemePart);
        if (isPackagedManaged) {
            Logger.d(mTag, "It seems that an addon I use (in package " + packageNameSchemePart
                    + ") has been removed. I need to reload stuff.");
            return true;
        }
    }
    return false;
}