我已经在一个GCM项目上,该项目能够在注册后从谷歌服务器接收和消息。
这个项目只包含一个包(com.example.gcm),所有的类(GCMIntentService…)都在这个包中声明。下面的代码描述了我的Manifest文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR PACKAGE NAME"
android:versionCode="1"
android:versionName="1.0" >
....
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
现在我正在尝试将这个GCM项目集成到我的主项目上,该项目包含至少4个子包。我采用了清单的相同配置,得到了如下内容
....
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<service android:name=".notification.GCMIntentService" />
在logcat中,我得到了GCM IntentService类:你的包名。GCMIntentService,这是不正确的,因为类在子包中。
如果我改变服务的名称,我把包的全名,我得到这个:
无法启动服务act=com.google.android.c2dm.intent.REGISTRATION cat=[xxx] flg=0x10Cmp =xxxx (has extras)}: not found
我已经读了很多线程,但没有什么有用的。
有办法解决这个问题吗?
想想,这应该对你有所帮助http://dexxtr.com/post/28188228252/rename-or-change-package-of-gcmintentservice-class
你应该定义你自己的Receiver类,然后添加到你的AndroidManifest.xml
public class GCMReceiver extends GCMBroadcastReceiver {
@Override
protected String getGCMIntentServiceClassName(Context context) {
return "com.example.gcm.GCMService";
}
}