Example usage for android.content Intent ACTION_MY_PACKAGE_REPLACED

List of usage examples for android.content Intent ACTION_MY_PACKAGE_REPLACED

Introduction

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

Prototype

String ACTION_MY_PACKAGE_REPLACED

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

Click Source Link

Document

Broadcast Action: A new version of your application has been installed over an existing one.

Usage

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);//www .  j  a  v  a  2  s. com

    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);// w w w  .  j av  a2  s.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 (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: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.j  a v a 2  s .  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);
    }
}