gpt4 book ai didi

java - GCM SERVICE_NOT_AVAILABLE 错误

转载 作者:行者123 更新时间:2023-11-29 21:21:35 26 4
gpt4 key购买 nike

我在我的 android 应用程序中使用 GCM,当我尝试向 GCM 注册设备时(使用命令 gcm.register(SENDER_ID))我收到 SEVICE_NOT_AVAILABLE 错误,我尝试了某人建议here (公认的解决方案)我确实获得了注册 ID。

为什么会这样?

Android list :

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appspot.smartgan"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<permission
android:name="com.appspot.smartgan.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.appspot.smartgan.permission.C2D_MESSAGE" />

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" >
<activity
android:name="com.appspot.smartgan.MainActivity"
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" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.appspot.smartgan" />
</intent-filter>
</receiver>

<service
android:name=".GcmIntentService"
android:enabled="true" />

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name="com.appspot.smartgan.LoginActivity"
android:label="@string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<activity
android:name="com.appspot.smartgan.ChildActivity"
android:label="@string/title_activity_child" >
</activity>
</application>

</manifest>

注册方法:

private void registerInBackground() {   
new AsyncTask<Void, Void, String>() {

@Override
protected String doInBackground(Void... params) {
String message = "";

try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
message = "Device registered, registration ID=" + regid;

Log.d("SMARTGAN_PLAY", "register completed");

// send registration id to the server
sendRegistrationIdToServer();

// Persist the regID - no need to register again.
storeRegistrationId(context, regid);
} catch (IOException e) {
message = "Error:" + e.getMessage();
}
return message;
}

}.execute(null, null, null);
}

最佳答案

我认为问题出在您的 Google API 项目中提到的允许的 IP 地址。请检查项目的详细信息,如果 restrict use to IP address 下存在 IP 地址,请将其删除。我遇到了类似的问题。

关于java - GCM SERVICE_NOT_AVAILABLE 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20662636/

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