Example usage for android.content Intent ACTION_PACKAGE_REMOVED

List of usage examples for android.content Intent ACTION_PACKAGE_REMOVED

Introduction

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

Prototype

String ACTION_PACKAGE_REMOVED

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

Click Source Link

Document

Broadcast Action: An existing application package has been removed from the device.

Usage

From source file:dev.ukanth.ufirewall.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;/*  www . j  av a2  s  . co  m*/
    }

    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Ignore application updates
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        if (!replacing) {
            // Update the Firewall if necessary
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
            Api.applicationRemoved(context, uid);
            /*Api.applicationRemoved(context,
             inputUri.getSchemeSpecificPart());*/
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                if (PackageManager.PERMISSION_GRANTED == context.getPackageManager()
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, added_package);
                }
            }
        }

    }
}

From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;//from   w  w  w.j a va  2  s .co  m
    }

    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Ignore application updates
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        if (!replacing) {
            // Update the Firewall if necessary
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
            Api.applicationRemoved(context, uid);
            Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context);
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                final PackageManager pkgmanager = context.getPackageManager();
                String label = null;
                try {
                    label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0))
                            .toString();
                } catch (NameNotFoundException e) {
                }
                if (PackageManager.PERMISSION_GRANTED == pkgmanager
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, label);
                }
            }
        }
    }
}

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:eu.faircode.adblocker.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);/*from   www  . j  a  v  a  2 s  .c o m*/

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:com.zhengde163.netguard.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);/*from   w  ww  .j a v a  2  s  .co m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:eu.faircode.netguard.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from  www.  ja va2s .  com

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (prefs.getBoolean("enabled", false))
                ServiceSinkhole.start("receiver", context);
            else if (prefs.getBoolean("show_stats", false))
                ServiceSinkhole.run("receiver", context);
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:com.master.metehan.filtereagle.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from w w w .  ja  v a2s.c  o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from  w w w  .  j a va  2  s  . co  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (true) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (prefs.getBoolean("enabled", false))
                ServiceSinkhole.start("receiver", context);
            else if (prefs.getBoolean("show_stats", false))
                ServiceSinkhole.run("receiver", context);
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

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:com.amaze.filemanager.fragments.AppsList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(false);//from  ww  w  .ja  va  2 s  .c o  m
    ic = new IconHolder(getActivity(), true, true);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    getActivity().registerReceiver(br, intentFilter);

}