我第一次尝试在我的应用程序中实现GCM,所以我按照这些步骤操作,并且出现了一个错误,导致我的应用程序无法在我的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商店中。
答案 0 :(得分:1)
我得到同样的错误,经过重新检查后,我忘了做以下两步:
将依赖项添加到项目级build.gradle:
classpath'com.google.gms:google-services:1.5.0-beta2'
将插件添加到您的应用级build.gradle:
申请插件:'com.google.gms.google-services'
答案 1 :(得分:0)
在您的项目AndroidManifest.xml
中,您已授予不存在的包com.example.gcm
的以下权限
<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
您的应用程序包是com.comgonzalovillarbaribus
,请尝试以下行:
<permission android:name="com.comgonzalovillarbaribus.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.comgonzalovillarbaribus.permission.C2D_MESSAGE" />
从com.example.gcm
AndroidManifest.xml
包名称
修改强>
您也可以在评论中提到这一点。
<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>