当用户安装我的应用程序时,我必须登录,因为我已经在清单中注册了 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>
接收器
@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);
}
这段代码有问题吗?