Java – Blocking of installed applications on Android devices

Blocking of installed applications on Android devices… here is a solution to the problem.

Blocking of installed applications on Android devices

I

got a list of package names and tags for installed applications in the database, and now I want to intercept installed applications and databases. Let’s say any application is removed from the device and then I want to change the database. For this, I’m using a broadcast receiver, but my code doesn’t work.

PackageManager pm = this.getPackageManager();
List < ApplicationInfo > list = getPackageManager().getInstalledApplications(PackageManager.PERMISSION_GRANTED);
for (int n = 0; n < list.size(); n++) {
    Apps.add(list.get(n).loadLabel(pm).toString());
    AppsP.add(list.get(n).packageName.toString());
    Log.w("Installed Applications", list.get(n).loadLabel(pm).toString());
    Log.w("Installed Applications Package", list.get(n).packageName.toString());

...
    In other class

public class PackageReceiver extends BroadcastReceiver {

@Override
        public void onReceive(Context context, Intent intent) {
             TODO Auto-generated method stub
            if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)) {
                String added_package = intent.getData().toString();
                Log.i("PackageReceiver", "Package Added = " + added_package);

} else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_REMOVED)) {
                String removed_package = intent.getData().toString();
                MyDBHelper DB = new MyDBHelper(context);
                Log.i("PackageReceiver", "Package removed = " + removed_package);
                DB.open();
                DB.deleteStmt = DB.db.compileStatement(QueryManager.ApplicationDelete);
                DB.deleteStmt.bindString(1, removed_package);
                DB.close();

}

Does it help??

Solution

What, what exactly are you trying to achieve?

If you are trying to prevent the uninstallation or installation of the app, I’m afraid you can’t do that. All you can do is request notifications.


Edit:

Did you also specify intent-filter in the list? For example:

<manifest>
    ....
    <application>
        ....
        <receiver>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED">
                <action android:name="android.intent.action.PACKAGE_REMOVED">
            </intent-filter>
        </receiver>
    </application>
</manifest>

Related Problems and Solutions