2014-05-24 3 views
0

Google developper 계정에서 토큰을 가져 오는 데 문제가 있습니다.Android GCM onRegistered가 호출되지 않았습니다.

Manifest.xml : 내 클래스 GcmIntentService에서 onRegistered GCM 방법은 호출되지 않습니다 은 ...

이 내 소스 코드

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.test.gcm" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <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="com.google.android.c2dm.permission.RECEIVE" /> 

    <permission 
     android:name="com.test.gcm.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.test.gcm.permission.C2D_MESSAGE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.test.gcm.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <receiver 
      android:name=".GcmBroadcastReceiver" 
      android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 

       <category android:name="com.test.gcm" /> 
      </intent-filter> 
     </receiver> 

     <service android:name=".GcmIntentService" /> 
    </application> 

</manifest> 

내 GcmIntentService.java :

package com.test.gcm; 

import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 

import com.google.android.gcm.GCMBaseIntentService; 

public class GcmIntentService extends GCMBaseIntentService { 
    public static String TAG = "GCMIntentService"; 
    public GcmIntentService(String senderId) { 
     super("************"); 
     Log.d("GCMIntentService", senderId); 
    } 

    @Override 
    protected void onError(Context arg0, String arg1) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    protected void onMessage(Context arg0, Intent arg1) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    protected void onRegistered(Context arg0, String arg1) { 
     // TODO Auto-generated method stub 
     Log.d("token", arg1); 
    } 

    @Override 
    protected void onUnregistered(Context arg0, String arg1) { 
     // TODO Auto-generated method stub 

    } 

} 

감사합니다.

답변

0

onRegistered은 수신자의 의도 필터에 com.google.android.c2dm.intent.REGISTRATION이 없기 때문에 호출되지 않습니다.

그것은해야한다 : 당신이 이전 등록 방법 (GCMRegistrar.register)를 사용하고 있는지 assuing 것

<receiver 
     android:name=".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.test.gcm" /> 
     </intent-filter> 
    </receiver> 

.

새 등록 방법 (GoogleCloudMessaging.register)을 사용하는 경우 register을 호출 할 때 동 기적으로 등록 ID를 얻으므로 onReceive 메서드가 필요하지 않습니다.

0

이 줄을 추가 했는데도 문제가 해결되지 않습니다. /. 가능하다면이 솔루션으로 토큰을 얻는 것이 성공할 것입니다. GCMRegistrar.register 메서드를 호출 할 때 onRegistered 메서드가 호출되는 것을 알고 있습니까?

이 나의 새로운 매니페스트입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.test.gcm" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <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="com.google.android.c2dm.permission.RECEIVE" /> 

    <permission 
     android:name="com.test.gcm.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.test.gcm.permission.C2D_MESSAGE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.test.gcm.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <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.test.gcm" /> 
      </intent-filter> 
     </receiver> 

     <service android:name=".GcmIntentService" /> 
    </application> 

</manifest> 

감사합니다.

관련 문제