クラスを使用してここで説明されている gcm を使用する新しい方法を使用しています。GoogleCloudMessaging
しかし、10回のうち9回はSERVICE_NOT_AVAILABLE
エラーが発生しています。一度だけデバイスを登録します。
07-01 14:24:55.907 2074-2090/com.deveyes.carrefour W/System.err: java.io.IOException: SERVICE_NOT_AVAILABLE
07-01 14:24:56.037 2074-2090/com.deveyes.carrefour W/System.err: at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
私のコードは、アクティビティ内で次のとおりです。
.....
gcmRegId = gcm.register(CarrefourConfig.GCM_SENDER_ID);
.....
後で、自動再試行を使用する必要があることを知りました。私はこれを読みましたが、このドキュメントは古いようです。新しい方法と同様に、IntentService を使用しなくなりました。それとも私たちですか?BroadcastReciever内で、メッセージを取得してユーザーに通知できます。
私はここで何を間違っていますか?
編集:
私のマニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<supports-screens
android:xlargeScreens="false"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.location" android:required="true" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<permission
android:name="com.deveyes.carrefour.android.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.deveyes.carrefour.android.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE" />
<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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Carrefour"
android:name=".CarrefourApplication">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKznwauzk_rNdKf7Qw0rjpmf4AWchCRwI" />
<activity
android:name=".ui.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.deveyes.carrefour" />
</intent-filter>
</receiver>
<!--service android:name=".services.CarrefourLocationService" /-->
</application>
私のメインアクティビティ:
private void registerBackground() {
new AsyncTask(){
@Override
protected Object doInBackground(Object[] objects) {
try {
if(gcm == null){
gcm = GoogleCloudMessaging.getInstance(context);
}
gcmRegId = gcm.register(CarrefourConfig.GCM_SENDER_ID);
Log.i(TAG,"regid:"+gcmRegId);
setRegistrationId(context,gcmRegId);
ServerUtilities.register(context,gcmRegId);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute(null,null,null);
}