BroadcastReceiver无法正常工作

Ale*_*lex 3 android broadcastreceiver

我已经实现了这个广播接收器:

public class ServiceManager extends BroadcastReceiver {
    private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
    private final String BOOT_ACTION_FIRST_LAUNCH = "android.intent.action.PACKAGE_FIRST_LAUNCH";
    private final String BOOT_ACTION_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";

    @Override
    public void onReceive(Context context, Intent intent) {
        // All registered broadcasts are received by this
        String action = intent.getAction();
        if (action.equalsIgnoreCase(BOOT_ACTION) || action.equalsIgnoreCase(BOOT_ACTION_FIRST_LAUNCH) || 
                action.equalsIgnoreCase(BOOT_ACTION_RESTARTED)) {
             // TODO: Action
        } 
    }

}
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<receiver android:name="package.service.ServiceManager" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
        <action android:name="android.intent.action.PACKAGE_RESTARTED" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

BOOT_COMPLETED操作正常,但是,PACKAGE_FIRST_LAUNCH和PACKAGE_RESTARTED无法正常工作.我需要在启动应用程序时启动广播接收器,这就是我使用这些操作的原因.但是,当我启动或重新启动应用程序时,接收器无法正常工作.它只在我重新启动手机时才有效.我的来源有什么问题吗?

Jen*_*ens 6

FYI:PACKAGE_FIRST_LAUNCH发送到安装程序包,即不管你用来安装应用程序-对于大多数最终用户,这将是Android Market中.

编辑:
哦,对于"PACKAGE_RESTARTED",将其中的一个打破<intent-filter>并添加一个

<data android:scheme="package"/>
Run Code Online (Sandbox Code Playgroud)

因为那个带有URI和显式方案.