1

クラスを使用してここで説明されている 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);
}
4

3 に答える 3

2

問題は次のとおりです。

以下の 3 つの場所すべてで同じパッケージ名を使用する必要がありますが、使用するcom.deveyes.carrefour.android場合と使用しない場合がありcom.deveyes.carrefourます。

<permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
<uses-permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE" />
...
    <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>

パッケージ名が の場合com.deveyes.carrefour、マニフェストを次のように変更します。

<permission android:name="com.deveyes.carrefour.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
<uses-permission android:name="com.deveyes.carrefour.permission.C2D_MESSAGE" />
...
    <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>
于 2013-07-01T14:35:44.293 に答える
1

GCM jar には、GCMRegistrar と呼ばれるものがあるはずです。そのメソッドを使用して GCM に登録する必要があります。以下はコードです、試してみてください

GCMRegistrar.checkDevice(this);
 GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
                DISPLAY_MESSAGE_ACTION));

        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
             GCMRegistrar.register(this, SENDER_ID); //this is where it registers
        } else {

            if (GCMRegistrar.isRegisteredOnServer(this)) {
                   Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG).show();
            } 

私はそれがあなたのために働くことを願っています

于 2013-07-02T15:09:15.037 に答える
0

私も同じ問題を抱えていました。

9/20 は SERVICE_NOT_AVAILABLE 例外をスローします。どうやらGoogle側のバグらしい。一部のデバイス (S3) で動作し、他のデバイス (LG L5) では動作しません。

ここをチェックしてください。

問題が解決するまでの間、一時的に古い API を使用することになると思います。

于 2013-08-25T16:52:36.273 に答える