Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – C2DM广播接收器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个有效的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) {

    ...

    }

}

表现

<manifest xmlns:android="http://scheR_259_11845@as.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手机上工作过,我找不到任何我正在做的事情.编写测试代码来证明这一点将是一件麻烦事,但我认为这是下一步.

编辑:
似乎与Force Quit有关.当我重新安装.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广播接收器全部内容,希望文章能够帮你解决android – C2DM广播接收器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。