我已根据文档在我的应用中实施了GCM推送通知,并且它随机工作。通常,它会喷出这个错误:
W/GMPM: Service connection failed: ConnectionResult{statusCode=SERVICE_MISSING_PERMISSION, resolution=PendingIntent{dee6afb: android.os.BinderProxy@c3e3718}, message=null}
发生此错误后,通常会在一段时间后开始工作。
我还没有找到任何有关此信息的信息,但我认为我的清单有问题......但它与google-GCM示例完全一样。
<manifest package="fi.pauli.myapp"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<permission
android:name="fi.pauli.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="fi.pauli.myapp.permission.C2D_MESSAGE"/>
<application
...
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
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="fi.pauli.myapp"/>
</intent-filter>
</receiver>
<service
android:name="fi.pauli.myapp.PushNotificationReceiverService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<service
android:name="fi.pauli.myapp.InstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="fi.pauli.myapp.RegistrationIntentService"
android:exported="false">
</service>
</application>
</manifest>
帮助,有人吗? :)
更新:我的RegistrationIntentService看起来像这样,每次都会得到一个令牌:
public class RegistrationIntentService extends IntentService
{
public RegistrationIntentService()
{
super("RegistrationIntentService");
}
public RegistrationIntentService(String name)
{
super(name);
}
@Override
protected void onHandleIntent(Intent intent)
{
try
{
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE);
if(MainActivity.userData != null ? MainActivity.userData.getId() != 0 : false)
{
if(!token.equals(MainActivity.userData.getPush_notification_id()))
{
MainActivity.userData.setPush_notification_id(token);
MainActivity.userData.setDeviceOS(2);
DataClient.writeFile("userData.json", new Gson().toJson(MainActivity.userData), getApplicationContext());
MainActivity.updatePushIdToServer(token);
}
}
}
catch (Exception e)
{
Log.e("RegistrationService", e.getMessage());
}
}
}
答案 0 :(得分:0)
我的清单中有更多此权限:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />