ACTION_PACKAGE_ADDED无效

时间:2015-10-27 07:08:25

标签: android broadcastreceiver android-manifest installation-package

我必须在用户安装我的应用程序时进行记录,因为我已经在清单中注册了ACTION_PACKAGE_ADDED广播并创建了一个接收器。但安装应用程序后接收器没有触发。我已尝试注册广播ACTION_PACKAGE_ADDED而不是PACKAGE_ADDED,它可以工作。我已经阅读了大部分关于此的SO问题并尝试了,但没有任何对我有用。我在下面给出了我的代码

清单

 <receiver android:name=".AppInstallReceiver">
        <intent-filter android:priority="1">
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>

Recevier

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

    if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
        String packageName = intent.getDataString();
        Log.i("Installed:", packageName + "package name of the program");
    }
    Log.d(TAG, "Action: " + intent.getAction());
    Uri data = intent.getData();
    Log.d(TAG, "The DATA: " + data);

}

此代码有问题吗?

0 个答案:

没有答案