gpt4 book ai didi

java - 无法使用 GCM 获取我的 InstanceID

转载 作者:太空狗 更新时间:2023-10-29 14:05:16 24 4
gpt4 key购买 nike

我第一次尝试在我的应用程序中实现 GCM,所以我按照这些步骤进行操作,但出现了一个错误,导致我的应用程序无法获得用于在我的 sv 中注册的 token 。

它说:

09-30 23:05:52.196 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ getGoogleAppId failed with status: 10
09-30 23:05:52.200 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ Uploading is not possible. App measurement disabled

我不知道是什么问题,我的 list 是正确的,我的 GCM_SENDER_ID 没问题。

这是我请求 token 的地方:

    // Set GCM
if (checkPlayServices()) {

InstanceID instanceID = InstanceID.getInstance(this);
String token = null;
try {
token = instanceID.getToken(Constants.GCM_SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
sendRegistrationToServer(token);
} catch (IOException e) {
e.printStackTrace();
}

}


...


private void sendRegistrationToServer(String token) {

HomeActivity.newRegID=token;
//WebServerRegistrationTask webServer=new WebServerRegistrationTask();
//webServer.execute();

// Create params
RequestParams params = new RequestParams();
params.add("regID",token);

// Doing the req
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
asyncHttpClient.post(Constants.WEB_SERVER_URL, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String key = responseBody.toString();
Log.e("key", key);
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
Log.e("error", "conexion");
}
});
}

这是我更新的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.comgonzalovillarbaribus" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.comgonzalovillarbaribus.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.comgonzalovillarbaribus.permission.C2D_MESSAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_home" >
</activity>
<activity
android:name=".ActivityHorariosLinea"
android:label="@string/title_activity_activity_horarios_linea">
</activity>
<activity
android:name=".ActivityHorariosParada"
android:label="@string/title_activity_activity_horarios_parada" >
</activity>
<activity
android:name=".ActivityListaTrabajos"
android:label="@string/title_activity_activity_lista_trabajos" >
</activity>

<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="com.comgonzalovillarbaribus"/>
</intent-filter>
</receiver>

<service
android:name=".GCM.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".GCM.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name=".GCM.RegistrationIntentService"
android:exported="false">
</service>
</application>

</manifest>

我已经在控制台中启用了 api。我的应用不在 Play 商店中。

最佳答案

我遇到同样的错误,重新检查后,我忘记执行以下 2 个步骤:

Add the dependency to your project-level build.gradle:

classpath 'com.google.gms:google-services:1.5.0-beta2'

Add the plugin to your app-level build.gradle:

apply plugin: 'com.google.gms.google-services'

关于java - 无法使用 GCM 获取我的 InstanceID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32879230/

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