PACKAGE_ADDED的BroadcastReceiver不起作用不起作用、PACKAGE_ADDED、BroadcastReceiver

2023-09-06 00:31:03 作者:一身清香味

我在清单中注册的广播接收器:

I have a broadcast receiver registered in Manifest:

<application ...>
    <receiver android:name="com.some.pkg.NewAppReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
        </intent-filter>
    </receiver>
</appcication>

和接收器:

public class NewAppReceiver extends BroadcastReceiver {

    private static final String TAG = "NewAppReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Intent: " + intent.getAction());
    }
}

和接收没事的时候我安装 APK 手动或从 Android Market的。为什么呢?

And nothing is received when I install APK manually or from the Android Market. Why?

推荐答案

你运行一个包含此的BroadcastReceiver安装其他应用程序之前,应用程序?

Did you run the app that contains this broadcastReceiver before installing the other apps?

开始在一些API版本,broadcastReceivers不会直到你执行应用程序的工作。把活动并执行它。

Starting at some API version, broadcastReceivers will not work till you execute the app. Put an activity and execute it.

另外,不要忘记添加以下到BroadcastReceiver的:

Also , don't forget to add the following into the broadcastReceiver:

<data android:scheme="package" />