Android覆盖安装,卸载移除广播监听器。未完待续

public class PackageReceiver extends BroadcastReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {
        // 安装
        if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
            String packageName = intent.getDataString();
            System.out.println("android.intent.action.PACKAGE_ADDED---------------" + packageName);
        }
        // 覆盖安装
        if (intent.getAction().equals("android.intent.action.PACKAGE_REPLACED")) {
            String packageName = intent.getDataString();
            System.out.println("android.intent.action.PACKAGE_REPLACED---------------" + packageName);
            try {
                Dysso mDysso = Dysso.createInstance(context);
                if (mDysso != null) {
                    mDysso.deleteToken();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        // 移除
        if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
            String packageName = intent.getDataString();
            System.out.println("android.intent.action.PACKAGE_REMOVED---------------" + packageName);
        }

    }
}


  "com.dy.rcp.PackageReceiver">
            
                "android.intent.action.PACKAGE_ADDED" />
                "android.intent.action.PACKAGE_REPLACED" />
                "android.intent.action.PACKAGE_REMOVED" />
                "package" />
            
        

        "android.permission.RESTART_PACKAGES"/>
        "android.permission.RECEIVE_BOOT_COMPLETED"/>

你可能感兴趣的:(android移动开发)