问题描述
我写一个Android 4.0.3程序与GCM的支持。
该应用程序注册罚款和从服务器发送的消息也似乎工作对我的广播接收器没有按'(获得一个消息ID从谷歌成功),然而的onReceive
方法吨得到解雇出于某种原因。
I am writing an Android 4.0.3 program with GCM support.The app registers fine and sending a message from the server also seems to work (getting "success" from Google with a message id), however the onReceive
method on my BroadcastReceiver doesn't get fired for some reason.
下面是明显的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jlieberman.nightwatch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.jlieberman.nightwatch.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.jlieberman.nightwatch.NightWatch"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.jlieberman.nightwatch" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
</application>
</manifest>
这里是广播接收器
:
package com.jlieberman.nightwatch;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
任何想法是什么原因造成的问题?
谢谢!
Any idea what is causing the problem?Thanks!
推荐答案
您有&LT;使用许可权的android:NAME =com.jlieberman.nightwatch.permission.C2D_MESSAGE/&GT;
在你的清单,但我没有看到你定义此权限。
You have <uses-permission android:name="com.jlieberman.nightwatch.permission.C2D_MESSAGE" />
in your manifest, but I don't see where you define this permission.
您应该加上:
&LT;允许机器人:名字=com.jlieberman.nightwatch.permission.C2D_MESSAGE
安卓的ProtectionLevel =签名/&GT;
这篇关于GcmBroadcastReceiver的onReceive方法不会触发在Android 4.0.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!