23

私は、新しい GCM を実装しようとしてます

デバイス登録 ID の取得で行き詰まりました。

私のアプリはGoogleサーバーに接続しようとし続けます.ここに私のエラーログがあります:

onReceive: com.google.android.gcm.intent.RETRY
GCM IntentService class: com.dombox.app.GCMIntentService
Acquiring wakelock
[GCMIntentService] start
Registering app com.dombox.app of senders _my_sender_id_
Releasing wakelock
onReceive: com.google.android.c2dm.intent.REGISTRATION
GCM IntentService class: com.dombox.app.GCMIntentService
Acquiring wakelock
[GCMIntentService] start
handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
Registration error: SERVICE_NOT_AVAILABLE
Scheduling registration retry, backoff = 912617 (768000)
Releasing wakelock

ID を要求する私のアクティビティ コードは次のとおりです。

    try{
        Log.i(TAG, "[checkNotifRegistration] checkDevice");
        GCMRegistrar.checkDevice(this);
        Log.i(TAG, "[checkNotifRegistration] checkManifest");
        GCMRegistrar.checkManifest(this);
        if (GCMRegistrar.isRegistered(this)) {
            Log.i(TAG, "[checkNotifRegistration] reg id : "+GCMRegistrar.getRegistrationId(this));
        }
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            // SENDER_ID is my project id into google account url
            GCMRegistrar.register(this, SENDER_ID);
            Log.i(TAG, "[checkNotifRegistration] reg id : "+GCMRegistrar.getRegistrationId(this));
        } else {
            Log.i(TAG, "[checkNotifRegistration] already registered as : " + regId);
        }
    } catch(Exception e){
        Log.e(TAG, "[checkNotifRegistration] Exception : "+e.getMessage());
        e.printStackTrace();
    }

ここに私のサービスコード

public class GCMIntentService extends GCMBaseIntentService {

private static final String TAG = "GCMIntentService";

public GCMIntentService() {
    super(SENDER_ID);
           // SENDER_ID is my project id into google account url
    // TODO Auto-generated constructor stub
    Log.d(TAG, "[GCMIntentService] start");
}


public GCMIntentService(String senderId) {
    super(senderId);
    // TODO Auto-generated constructor stub
    Log.d(TAG, "[GCMIntentService] start - sender Id : "+senderId);
}
}

そして、ここに私のAndroidマニフェストがあります:

<permission android:name="com.dombox.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.dombox.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        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.myapp.app" />
        </intent-filter>
    </receiver>

<service android:name=".GCMIntentService" android:enabled="true"/>

    <activity
        android:name=".activity.Myapp"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

私は Google の指示に従っていますが、この SERVICE_NOT_AVAILABLE エラーに固執しました。

私は何を間違っていますか?

4

6 に答える 6

39

問題はコード関連ではなく、テスト電話へのリンクでした。 テスト用のスマートフォンには SIM がなく、時計も設定されていませんでした。そのため、Google は間違った時間で登録することはできません。

Android仮想デバイスを使用して、Google APIを使用し、テスト用の電話クロックを設定することで、登録IDを取得できました。

于 2012-07-11T08:43:00.943 に答える
7
android:enabled="true"  

これを削除します^

これをマニフェストにまだ追加していない場合

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8"

GCMIntentService の 2 番目のコンストラクターは必要ありません。これだけ

public GCMIntentService() {         
 super(SENDER_ID);  }

SENDER_ID が、Google コードの Web サイトと GCM サービスの閲覧中に、ブラウザから URL からコピーされた番号であることを確認してください。

于 2012-07-09T16:33:32.073 に答える
3

企業のファイアウォールの内側にいる場合、GCM が使用する一部のポートがローカル ワイヤレス経由での通信を許可されていない可能性があることに注意してください。エミュレータを最初に動作させようとしたときに、この問題が発生しました。以下にリストされているポートを通過できる特別な IP を取得する必要がありました。


注: 組織にインターネットとの間のトラフィックを制限するファイアウォールがある場合、Android デバイスがメッセージを受信できるように、GCM との接続を許可するようにファイアウォールを構成する必要があります。開くポートは、5228、5229、および 5230 です。GCM は通常、5228 のみを使用しますが、5229 と 5230 を使用することもあります。GCM は特定の IP を提供しないため、含まれるすべての IP アドレスへの発信接続をファイアウォールが受け入れるようにする必要があります。 Google の ASN の 15169 にリストされている IP ブロック内。

http://developer.android.com/google/gcm/gcm.html

于 2013-05-30T14:03:38.953 に答える
2

私はこの問題を抱えていました...私の解決策は、インターネット接続を無効にして電話サービスを使用することでした。

于 2013-04-05T03:53:15.423 に答える
1

genymotion でアプリケーションを実行すると、この問題が発生しました。ここにあるようにGoogle Playサービスをインストールすると、すべて正常に機能しました。

于 2014-11-11T20:59:35.107 に答える