C2DM广播接收器

Ayy*_*yrk 7 android

我有一个有效的C2DM应用程序.我在创建新的C2DM应用程序时重用了相同的包名.

它的工作原理除外,当应用程序未运行时,不会调用BroadcastReceiver.也就是说,如果我运行应用程序并向其发送C2DM消息,则一切正常.但是在强制退出后,不再调用BroadcastReceiver.

我查看了很多示例,并将旧清单中的所有内容与新清单进行了比较.特别注意类别中使用的包名,意图服务等.

问题:是否存在常见的C2DM编码/配置错误导致应用程序强行退出后未调用BroadcastReceiver?

在强制退出我的应用程序后发送C2DM消息时,我确实得到了这个日志:

01-11 00:54:43.580:WARN/GTalkService(286):[DataMsgMgr]广播意图回调:result = CANCELED forIntent {act = com.google.android.c2dm.intent.RECEIVE cat = [com.aawwpcd.pcd3] (有额外的)}

在强制退出应用程序后,我为每个发送到设备的C2DM消息获取其中一个消息.

它似乎意图进入但未传递给我的BroadcastReceiver.

编辑:

以下是Manifest和BroadcastReceiver的相关位:

BroadcastReciever

package com.aawwpcd.pcd3.c2dm;

import ...

public class C2DMBroadcastReceiver extends BroadcastReceiver {

    @Override
    public IBinder peekService(Context myContext, Intent service) {
        return super.peekService(myContext, service);
    }

    public C2DMBroadcastReceiver() {
        super();
    }

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

    ...

    }

}
Run Code Online (Sandbox Code Playgroud)

表现

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.aawwpcd.pcd3"
      android:versionCode="250"
      android:versionName="ICSPCD3">

<uses-sdk android:minSdkVersion="13"
          android:targetSdkVersion="14"/>

<permission android:name="com.aawwpcd.pcd3.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.aawwpcd.pcd3.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<application android:name=".PCD3Application"
             android:label="@string/app_name"
             android:icon="@drawable/pcdlauncher"
             android:theme="@android:style/Theme.Holo">

    <activity android:name=".honeycombpcd3.FullScheduleActivity"
              android:label="@string/app_namefull"
            >

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

    </activity>

    <!-- Only C2DM servers can send messages for the app. If permission is not
    set - any other app can generate it -->
    <receiver android:name=".c2dm.C2DMBroadcastReceiver"
              android:permission="com.google.android.c2dm.permission.SEND">

        <!-- Receive the actual message -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            <category android:name="com.aawwpcd.pcd3"/>
        </intent-filter>

        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
            <category android:name="com.aawwpcd.pcd3"/>
        </intent-filter>

    </receiver>

</application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

编辑:这可能是3.x中的新功能吗?如上所述,我的问题始于这个新的应用程序 - 为3.x编写.我想要的是C2DM甚至在应用程序没有运行时调用BroadcastReceiver.我没有看到.这可能是3.x的变化吗?它之前在2.3.x手机上工作过,我找不到任何我正在做的事情.编写测试代码来证明这一点将是一件麻烦但我认为这是下一步.

编辑:似乎与Force Quit相关.当我重新安装.apk然后向设备发送c2dm消息时,我没有任何问题; 广播接收器拿起它.在这种情况下,当C2DM进入时,应用程序尚未运行,但一切都按预期工作.我唯一的问题是在我强制退出应用程序之后.之后的C2DM消息不被BroadcastReceiver拾取.

Dor*_*avi 10

看看 /sf/answers/497602801/

并在Android 3.1发行说明http://developer.android.com/about/versions/android-3.1.html#launchcontrols

从3.1开始,Force停止的应用程序默认情况下不再由C2DM重新启动.在强制关闭后请求重新启动有一个新标志.


Jus*_*ler 1

在“强制退出”接收器几次后,您是否一直在监视 logcat?您可能会看到一条“Bad Process”消息,暗示您的接收器崩溃次数过多,Android 将不再向其发送意图。正如您在编辑中暗示的那样,重新启动手机/重新安装应用程序可以解决此问题。