简体   繁体   English

截取Android设备上已安装的应用程序

[英]Interception of Installed Applications on android device

I got the list of Package name & Label of installed application in database, Now I want to interception with installed application and database. 我在数据库中获得了已安装应用程序的包名称和标签列表,现在我想拦截已安装的应用程序和数据库。 Suppose any application delete from device then I want changes in Database. 假设任何应用程序从设备中删除然后我想要更改数据库。 for that i am using broadcast receiver but my code not works. 因为我使用广播接收器,但我的代码不起作用。

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();

            }

any help?? 任何帮助?

What, exactly are you trying to achieve? 你想要实现什么?

If you are trying to prevent uninstallation or installation of apps, then I'm afraid you cannot do that. 如果您试图阻止卸载或安装应用程序,那么我担心您不能这样做。 All you can do is request to be notified. 您所能做的就是要求收到通知。


EDIT: 编辑:

Have you also specified the intent-filter in your manifest? 您是否还在清单中指定了intent-filter? 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>
    intentAPP.addAction(Intent.ACTION_PACKAGE_ADDED);
            intentAPP.addAction(Intent.ACTION_PACKAGE_CHANGED);
            intentAPP.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
            intentAPP.addAction(Intent.ACTION_PACKAGE_INSTALL);
            intentAPP.addAction(Intent.ACTION_PACKAGE_REMOVED);
            intentAPP.addAction(Intent.ACTION_PACKAGE_REPLACED);
            intentAPP.addAction(Intent.ACTION_PACKAGE_RESTARTED);

//for storing list in db

    for (int i = 0; i < AppsP.size() && i < Apps.size(); i++) {

                    DB.insertStmt.bindString(1, URLDecoder.decode(AppsP.get(i)));
                    DB.insertStmt.bindString(2, URLDecoder.decode(Apps.get(i)));
                    DB.insertStmt.bindString(3, 1 + "");
                    DB.insertStmt.bindString(4, "false");
                    DB.insertStmt.executeInsert();

                }

//adding package notification
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)) {
            String added_package = intent.getData().toString();
            Log.i("PackageReceiver", "Package Added = " + added_package);
            Intent Intent_add = new Intent();
            Intent_add.setClass(context, ServiceAppsAdd.class);
            Intent_add.putExtra("Package_Name", added_package.substring(8));
            Intent_add.putExtra("Status", status_new);
            context.startService(Intent_add);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM