gpt4 book ai didi

android - C2DM广播接收器

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:05 24 4
gpt4 key购买 nike

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

除了现在当应用程序未运行时 BroadcastReceiver 不会被调用外,它可以正常工作。也就是说,如果我运行该应用程序并向其发送 C2DM 消息,一切都会正常进行。但在强制退出后,不再调用 BroadcastReceiver。

我看过很多示例,并将旧 list 中的所有内容与新 list 进行了比较。特别注意类别、 Intent 服务等中使用的包名称。

问题:是否存在一个常见的 C2DM 编码/配置错误,导致在强制退出应用后 BroadcastReceiver 未被调用?

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

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

在强制退出应用程序后,我发送到设备的每条 C2DM 消息都会得到其中一个。

看起来 Intent 正在传入,但没有传递到我的 BroadcastReceiver。

编辑:

这里是来自 Manifest 和 BroadcastReceiver 的相关位:

广播接收者

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) {

...

}

}

list

<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>

编辑:这可能是 3.x 中的新内容吗?如上所述,我的问题始于这个为 3.x 编写的新应用程序。我想要的是 C2DM 即使在应用程序未运行时也能调用 BroadcastReceiver。我没有看到。这可能是 3.x 的变化吗?它以前在 2.3.x 手机上以这种方式工作,但我找不到任何不同的地方。编写测试代码来证明这一点会很麻烦,但我想接下来就是了。

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

最佳答案

看看 https://stackoverflow.com/a/7108611

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

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

关于android - C2DM广播接收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8814817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com