gpt4 book ai didi

android - GCM 无效发件人错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:00 27 4
gpt4 key购买 nike

我在一个神秘的问题上卡住了一段时间。所以我在我的 android 应用程序中实现了 GCM,但我收到了一个 INVALID_SENDER 错误。

  • 我的 SENDER_ID 是来自 google 项目 url 的 ID。
  • Android 推送通知已开启

奇怪的是,我已经有一个注册 ID 可以向其发送通知。所以我的控制台看起来像这样:

03-26 09:39:20.233: I/<test>(19761): Already registered: APA91bG6-   O3OnZt50EAjYvJ5KETv3qAlPOn2SfOPXez7SLAmaAOkHTN6EMDJb91gFIWkftZkJiub6UoEk4O-  WQP7kk2oZGQjZ1VCZZS0WddQtjFaCfYfZfb7SEw3IS1sd4caJcdZE4LA1F0hxzc7Ss1UiYHXX-XXXX
03-26 09:48:23.522: I/<test>(19925): GCMIntentService
03-26 09:39:20.670: I/<test>(19761): on Error INVALID_SENDER

在 onCreate 中:

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
Log.i("<test>", "registering");
GCMRegistrar.register(this, "2194354949XX");
} else {
Log.i("<test>", "Already registered: " + regId);
}

广播接收者:

 public class GCMBroadcastReceiver extends com.google.android.gcm.GCMBroadcastReceiver{
@Override
protected String getGCMIntentServiceClassName(Context context){
return "be.XXX.XXX.system.GCMIntentService";
}
}

GCMIntentService:

 public class GCMIntentService extends GCMBaseIntentService {
@Override
protected void onError(Context arg0, String errorId) {
Log.i("<test>","on Error " + errorId);
}

@Override
protected void onMessage(Context arg0, Intent intent) {
Log.i("<test>","onMessage " + intent.getExtras().toString());
}

@Override
protected void onRegistered(Context arg0, String regId) {
Log.i("<test>","Registration id: " + regId);
}

@Override
protected void onUnregistered(Context arg0, String regId) {
Log.i("<test>","onUnregistered " + regId);
}

public GCMIntentService() {
super("2194354949XX");
Log.i("<test>","GCMIntentService ");
}
}

list :

 <permission
android:name="com.XX.XX.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.smstiming.hezemans.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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />



<receiver android:name="be.XX.XX.system.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="com.smstiming.hezemans" />
</intent-filter>
</receiver>

<service android:name="be.XX.XX.system.GCMIntentService" />

最佳答案

终于解决了这个问题。不小心尝试使用“项目 ID”而不是“项目编号”。 Google Developer Console 在概览页面上同时提供了这两种方法,请确保您使用的是正确的。

关于android - GCM 无效发件人错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15632924/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com