我有一个工作C2DM应用。 创建一个新的C2DM的应用程序,当我重复使用相同的包名。
I had a working C2DM application. I reused the same package name when creating a new C2DM application.
它的工作原理除了现在当应用程序没有运行的BroadcastReceiver不会被调用。也就是说所有的工作,如果我运行应用程序,发送C2DM消息。但生效后退出的BroadcastReceiver不再调用。
It works except now the BroadcastReceiver doesn't get called when the application is not running. That is to say it all works if I run the application and send it C2DM messages. But after a force quit the BroadcastReceiver is no longer called.
我已经看过很多例子,相比一切都在我的老舱单新的。支付特别注意包装的分类使用的名称,意图服务等。
I have looked at a lot of examples and compared everything in my old manifest to the new one. Paying extra attention to package names used in categories, Intent Services, etc..
问:是否有一个共同的C2DM编码/配置错误,导致的BroadcastReceiver不会被调用后的应用程序是强制退出
Question: Is there a common C2DM coding/config mistake that results in the BroadcastReceiver not being called after an app is force quit?
我得到这个日志的猫,当我发送C2DM消息后,强制退出我的应用程序的:
I do get this log cat when I send a C2DM message after force quit of my application:
01-11 00:54:43.580:WARN / GTalkService(286):[DataMsgMgr]广播意图回调:结果=已取消forIntent {行为= com.google.android.c2dm.intent.RECEIVE猫= [com.aawwpcd .pcd3](有群众演员)}
01-11 00:54:43.580: WARN/GTalkService(286): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.aawwpcd.pcd3] (has extras) }
我得到的那些我发送到设备力量退出应用软件后每个C2DM消息之一。
I get one of those for each C2DM message I send to the device after force quitting the application.
它看起来像意图进来的,但没有被传递给我的BroadcastReceiver。
It looks like the intent is coming in but not being passed to my BroadcastReceiver.
编辑:
下面是从清单和BroadcastReceiver的初步认识了位:
Here are the relavant bits from the Manifest and 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://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的手机,我无法找到任何东西我做的一样。这将是一个麻烦,编写测试code来证明这一点,但认为是下一个,我猜。
Could this be something new in 3.x ? As stated above my problems started with this new application - written for 3.x. What I want is for the C2DM to call the BroadcastReceiver even when the application is not running. I am not seeing that. Could it be a 3.x change? It worked this way before on 2.3.x phones and I can't find anything I am doing different. It will be a hassle to write the test code to prove this but that's next I guess.
编辑: 似乎强制退出有关。我没有任何问题,当我重新安装apk文件,然后发送装置的C2DM消息;广播接收器接收它。在这种情况下,应用程序尚未运行时,C2DM进来但一切都如预期。我遇到的唯一的问题是在我强制退出应用程序。后未拾取的的BroadcastReceiver C2DM消息。
Seems related to Force Quit. I don't have any problem when I re-install the .apk and then send the device a c2dm message; the Broadcast receiver picks it up. In this case the application was not already running when the C2DM came in yet everything worked as expected. The only problem I am having is after I force quit an application. C2DM messages after that are not picked up by the BroadcastReceiver.
推荐答案
看一看 http://stackoverflow.com/a/7108611
而在Android的3.1版本说明http://developer.android.com/about/versions/android-3.1.html#launchcontrols
And at Android 3.1 release notes http://developer.android.com/about/versions/android-3.1.html#launchcontrols
由于3.1, 强制停止应用程序不再会通过重新启动C2DM默认。 有一个新的标志,请求重新启动强制关闭后。
As of 3.1, Force stopped apps no longer get restarted by C2DM by default. There is a new flag for requesting a restart after force-close.
相关推荐
最新文章