Android GCM Reg IDが取得できない
Android GCMでメッセージを送るでGCMの本当にさわりのGoogleさんのコードを紹介しましたが、ちょっとしたことでつまづきやすいので、書いておきます。。。
アクティビティでまずregIdを登録します。
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, PlacesConstants.SENDER_ID);
} else {
// Device is already registered on GCM, check server.
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
tv.append(getString(R.string.already_registered) + "\n");
}
しかし、いつまでもregIdが帰ってきません。
どうやらGCMIntentServiceが呼ばれていないようです…
ちなみに今日(2013/07/17)調べたところ、
GCMRegistrar.getRegistrationId(this)
はDeprecatedされたようです…。
残念。GCM Registration IDの取得を見てみてください。
AndroidManifest.xmlを見直すと
<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="my.application" />
</intent-filter>
</receiver>
category android:name=”my.application”のmy.applicationの部分に、正しくアプリケーション名を書かなければいけなかったのですが、違う名前が入ってしまってました(^_^;
