广播接收机无法接收意向接收机、意向

2023-09-04 12:13:44 作者:英国酒友。

我有两个应用程序上,我有完全的控制。两者都使用相同的证书签署,都使用完全相同的意图过滤器。其中发送广播从一个片段,另一种是想接受它,并做一些事情。然而,这是行不通的:

I have two apps that I have complete control over. Both are signed with the same cert and both use the exact same intent filter. One sends the broadcast from a fragment, the other is suppose to receive it and do something. This however is not working:

Strings.FILTER_INIT_REGISTER = "com.app.FILTER_INIT_REGISTER"

Intent intent = new Intent(Strings.FILTER_INIT_REGISTER);
getActivity().sendBroadcast(intent);

我已经注册了接收器为包含ReportingReceiver类应用程序的清单应用程序标记:

I have registered the receiver in the Manifest app tag for the app containing the ReportingReceiver class:

<receiver             
    android:name=".receivers.ReportingReceiver"
    android:exported="true"
    >
        <intent-filter>
            <action android:name="com.app.FILTER_INIT_REGISTER" />
            <category android:name="android.intent.category.DEFAULT" />                
        </intent-filter>
</receiver>

好奇为什么ReportingReceiver类是没有得到的意图电话吗?

Curious why the ReportingReceiver class is not getting the intent call?

推荐答案

如果您的应用程序只有那么一个服务,接收器不会在Android的3.1和更高版本。其原因是,该系统不会发送广播意图应用是在停止状态。应用程序是在停止状态是第一次安装时。它是从删除停止状态当用户手动启动该应用程序的第一次。它返回到停止状态如果用户强制应用程序停止使用该应用程序管理器工具。

If your application only has a service and receivers then this won't work in Android 3.1 and later. The reason is that the system will not send broadcast Intents to application that are in the STOPPED STATE. An application is in the STOPPED STATE when it is first installed. It is removed from the STOPPED STATE when the user manually starts the application for the first time. It is returned to the STOPPED STATE if the user forces the application to stop using the application manager tool.

由于您的应用程序没有活动,也没有办法为用户的开始了。因此,它将永远不会停止状态出来。

Since your application has no Activities, there is no way for the user to "start" it. Therefore it will never come out of the stopped state.

请参阅http://developer.android.com/about/versions/android-3.1.html#launchcontrols