不能让我的GCM实例id [英] Cant get my InstanceID with GCM
问题描述
我想在我的应用程序首次实行GCM,所以我遵循的步骤,并有使我的应用程序没有获得注册的标记在我的SV错误。
I'm trying to implement GCM in my app for the first time, so I've followed the steps and there's an error that make my app doesn't get the token for registration in my sv.
它说:
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
我不知道是什么问题,我的清单是正确的,我的 GCM_SENDER_ID
就可以了。
下面是我问我的令牌:
// 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");
}
});
}
这是我的新清单:
<?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商店。
I already have the api enabled in the console. My app is not in the play store.
推荐答案
我得到了同样的错误,复核后,我忘了做以下2步:
I got same error, after recheck, i forgot to do 2 steps below:
添加的依赖到你的项目级的build.gradle:
Add the dependency to your project-level build.gradle:
类路径'com.google.gms:谷歌服务:1.5.0-β2
classpath 'com.google.gms:google-services:1.5.0-beta2'
插件添加到您的应用程序级的build.gradle:
Add the plugin to your app-level build.gradle:
应用插件:'com.google.gms.google服务
apply plugin: 'com.google.gms.google-services'
这篇关于不能让我的GCM实例id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!