質問

私はこの問題について他の答えを試みますが、解決することはできません。送信者IDが正しく、権限が追加され、APIキーがtrueです。

私はプロジェクトを作成するためにこの投稿を使用します:http://developer.android.com/guide/google/gcm/gs.html#server-app

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, SENDER_ID);
      regId = GCMRegistrar.getRegistrationId(this);
    } else {
      Log.v(TAG, "Already registered");
    }
    String did = getDeviceID();

空の文字列を返します。

役に立ちましたか?

解決

あなたは持っていますか GCMIntentService 定義された 正しく あなたのアプリのルートパッケージで?

<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="my_app_package" />
  </intent-filter>
</receiver>

次のことを確認してください "my_app_package" アプリのメインパッケージと同じであるか、idが空の文字列を返します。

また、それに注意してください

    GCMRegistrar.register(this, "...");

非同期です。したがって、呼び出し GCMRegistrar.getRegistrationId(this) その直後は信頼できないので、避けてください。

Idはあなたに放送コールバックを介して到着します GCMIntentService, 、登録手続きの一環として。そこから、gcm/fcmキーを好きな場所に保存し、アプリケーションの他の部分(通常はサーバー上)で使用できます。

他のヒント

アプリケーションが初めて起動した場合は、gcmintentservice.javaファイルでonRegisteredコールバックを待つ必要があります。

GCMRegistrar.register(this, SENDER_ID);
// Android does NOT wait for registration ends and executes immediately line below
// So your regId will be empty.
regId = GCMRegistrar.getRegistrationId(this);
.

gcmintentservice.java:

@Override
protected void onRegistered(Context c, String regId) {
    // You can get it here!
}
.

編集:GCMライブラリのGCMライブラリ(Google Play Services Libraryにバンドルされている)の新しいバージョンは、応答を待ち、登録IDを返します。だからこの答えは古いGCMライブラリのためのものです。

私は1日の闘争後に同じ問題があります私は解決策を見つけました。まず私のGCM関連のコードをマイパッケージに入れて、androidmanifest.xml

の私のパッケージに従って変更を加える

私はあなたに簡単な例を与えます。私のプロジェクト名はgcmexampleです。/ P>

私のGCM関連クラスファイルを私の2番目のパッケージに

に登録IDを取得していません

私のGCM関連クラスのような1.GCMintentService、2. Severtities、3. Componatizes 4. WakeLockerがマイメインパッケージに入れるCom.example.gcmexample

また私のandroidmanifest.xml

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.VIBRATE" />

     <permission android:name="com.example.GCMExample.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

     <uses-permission android:name="com.example.GCMExample.C2D_MESSAGE" />

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
        <!-- Receives the actual messages. -->
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <!-- Receives the registration id. -->
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        <category android:name="com.example.GCMExample" />
      </intent-filter>
</receiver>  

<service android:name="com.example.GCMExample.GCMIntentService" />
.

送信者の登録済みの送信者のcom.example.ilkgcm "my_sender_id" - このエラーは、12文字のコードになる有効な送信者IDにあなたの 'my_sender_id'を変更していないことを示唆しています。

登録から応答を得ていない場合。正しく

例えばReceiverクラス名は次のとおりです。これは簡単な解決策です。SRCエリアでファイル名を変更するだけです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top