Example usage for android.content Intent ACTION_PACKAGE_DATA_CLEARED

List of usage examples for android.content Intent ACTION_PACKAGE_DATA_CLEARED

Introduction

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

Prototype

String ACTION_PACKAGE_DATA_CLEARED

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

Click Source Link

Document

Broadcast Action: The user has cleared the data of a package.

Usage

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:org.wso2.iot.agent.events.listeners.ApplicationStateListener.java

@Override
public void onReceive(Context context, final Intent intent) {
    String status = null;/*from w  ww.j  av a2s  . c  om*/
    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);
        }
    }
}