问题描述
我试图做一个GCM客户端,注册是好的。我也成功地从服务器发送消息。但是,客户不会开始这个意图。它说
我的意图
public class GCMService extends IntentService {
$ b $ public GCMService(String name){
super(GCMService);
}
protected void onHandleIntent(意图意图){
Bundle extras = intent.getExtras();
字符串messageType = gcm.getMessageType(intent);
android.util.Log.i(hi,test);
if(!extras.isEmpty()){
if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)){
Logger.logInUI(tag,Received:+ extras的ToString());
}
}
GCMReceiver.completeWakefulIntent(intent);
而我的接收器
public class GCMReceiver extends WakefulBroadcastReceiver {
public void onReceive(Context context,Intent intent){
ComponentName comp = new ComponentName(context.getPackageName (),
GCMService.class.getName());
startWakefulService(context,(intent.setComponent(comp)));
Logger.log(hi,eetett);
setResultCode(Activity.RESULT_OK);
$ / code $ / pre
最后,我的清单
<?xml version =1.0encoding =utf-8?>
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =dol.framework
android:versionCode =1
android:versionName =1.0>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
< uses-permission android:name =android.permission.INTERNET/>
<使用权限android:name =android.permission.GET_ACCOUNTS/>
< uses-permission android:name =com.google.android.c2dm.permission.RECEIVE/>
<使用权限android:name =android.permission.WAKE_LOCK/>
< permission android:name =dol.framework.gcm.permission.C2D_MESSAGE
android:protectionLevel =signature/>
<使用权限android:name =dol.framework.gcm.permission.C2D_MESSAGE/>
< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =18/>
< application
android:allowBackup =true
android:icon =@ drawable / ic_launcher
android:name =dol.framework.widget .DolApplication
android:label =Dol Framework
android:theme =@ style / AppTheme>
< activity
android:name =dol.framework.activity.DebugActivity
android:configChanges =orientation | keyboardHidden | screenSize
android:label =@ string / app_name
android:theme =@ android:style / Theme.Black.NoTitleBar.Fullscreen>
< intent-filter>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< receiver
android:name =dol.framework.GCMReceiver
android:permission =com.google.android.c2dm.permission.SEND>
< intent-filter>
< category android:name =dol.framework/>
< / intent-filter>
< / receiver>
< service android:name =dol.framework.GCMService/>
< / application>
< / manifest>
对不起,文字墙。 GCMService和GCMReceiver都位于我的包的顶部(dol.framework)。我究竟做错了什么?除了那些,我没有太多。只注册设备,然后我正在向该设备发送消息。日志在顶部打印消息,但什么都不做。我不应该开始服务还是什么?我没有看到有关示例的任何内容。
解决方案在您为GCM定义和使用的权限中,您有dol.framework。 gcm.permission。它应该是dol.framework.permission,因为你的应用程序的包是dol.framework。
I am trying to make a GCM client, registration is fine. I am also successfully sending messages from server. However, the client does not start the intent. It says
My Intent
public class GCMService extends IntentService{
public GCMService(String name) {
super("GCMService");
}
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
String messageType = gcm.getMessageType(intent);
android.util.Log.i("hi","test");
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Logger.logInUI(tag, "Received: " + extras.toString());
}
}
GCMReceiver.completeWakefulIntent(intent);
}
}
And my receiver
public class GCMReceiver extends WakefulBroadcastReceiver {
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GCMService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
Logger.log("hi","eetett");
setResultCode(Activity.RESULT_OK);
}
}
And finally my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dol.framework"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="dol.framework.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="dol.framework.gcm.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name="dol.framework.widget.DolApplication"
android:label="Dol Framework"
android:theme="@style/AppTheme" >
<activity
android:name="dol.framework.activity.DebugActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="dol.framework.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="dol.framework" />
</intent-filter>
</receiver>
<service android:name="dol.framework.GCMService"/>
</application>
</manifest>
Sorry for the wall of text. Both GCMService and GCMReceiver is at top of my package (dol.framework). What am I doing wrong? Other than those, I am not doing much. Only registering the device and then I am sending a message to this device. Log prints the message at top but does nothing. Shouldn't I start service or something? I didn't see anything related on examples.
解决方案 In the permission you defined and used for GCM you have dol.framework.gcm.permission. It should be dol.framework.permission, since your app's package is dol.framework.
这篇关于Google云消息接收方意图不会启动(广播意图回调:result = CANCELED forIntent)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!