2012-06-30 5 views
5

私はGoogleのAndroid開発者向けサイトからGoogle's GCMの手順を始めるフィニッシュしようとしています。リークIntentReceiverエラー()

私のデバイスが登録しようとすると、それは以下の理由で失敗します。

活動は、もともとここに登録されたcom.google.android.gcm.GCMBroadcastReceiverからIntentReceiverが漏れました。 unregisterReceiverへの電話がありませんか?

これはコードです:

GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this); 
final String regId = GCMRegistrar.getRegistrationId(this); 
if (regId.equals("")) { 
    GCMRegistrar.register(this, senderId); // <-- It fails here 
} else { 
    Log.v("GCM", "Already registered"); 
} 

任意のアイデア?

私は間違っていますか?

更新

これが私のマニフェストです:私は正しく私の権限を設定していないとき

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.sample" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="com.sample.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 

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

     <activity 
      android:name=".sample" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:theme="@android:style/Theme.NoTitleBar" android:name=".Main" android:screenOrientation="portrait" /> 
     <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.sample" /> 
      </intent-filter> 
     </receiver>    
     <service android:name="com.sample.GCMIntentService" /> 
     <uses-library android:name="com.google.android.maps" /> 
    </application> 

</manifest> 
+0

だけで推測し、あなたのプロジェクトのクラスGCMIntentServiceを持っているか、そしてこのクラスは、パッケージ名com.sample.GCMIntentServiceがありますか? – azgolfer

答えて

12

最後に動作します。

私がする必要があるのは、私がここで見つかりGCMRegistrar.register()

を呼んでいる同じコンテキストでonDestroy()方法でGCMRegistrar.onDestroy(this)への呼び出しである:あなたのサポートのためのLeaked IntentReceiver in Google Cloud Messaging

感謝:)

0

これは私に起こりました。 私はマニフェストに追加することによってそれを解決:

<permission android:name="PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="PACKAGE.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
+0

私はすでにマニフェストでこれらの権限を持っていますが、それでも失敗します – histeria

+0

あなたのマニフェストを投稿するかもしれませんか? – hyotam

+0

確かに。私は更新されてきた私のポスト – histeria

0

私は、このマニフェストでの作業、それを持っている:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="PACKAGENAME" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

    <permission android:name="PACKAGENAME.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="PACKAGENAME.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <permission android:name="android.permission.WAKE_LOCK" android:protectionLevel="signatureOrSystem"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK"/> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <service android:name="PACKAGENAME.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="PACKAGENAME" /> 
    </intent-filter> 
</receiver> 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

もGCMBaseIntentServiceから延びあなたのクラスに空のコンストラクタを追加します。私の場合、名前は:GCMIntentServiceです。

+0

あなたの引数なしのコンストラクタは、スーパーコンストラクタにどのような送信者IDを渡しますか? GCMBaseIntentService()には引数なしのコンストラクタはありません。 – jph

+0

google apiプロジェクトのプロジェクトID – Klaasvaak

2

あなたはすべきです以下のようなアクティビティコンテキストの代わりに、アプリケーションコンテキストを使用します。

public String registerPushAccount() 
{ 
    GCMRegistrar.checkDevice(getApplicationContext()); 
    GCMRegistrar.checkManifest(getApplicationContext()); 
    if (GCMRegistrar.isRegistered(getApplicationContext())) 
    { 
     Log.d("info", GCMRegistrar.getRegistrationId(getApplicationContext())); 
    } 
    String regId = GCMRegistrar.getRegistrationId(getApplicationContext()); 
    if (regId.equals("")) 
    { 
     regId = GCMRegistrar.getRegistrationId(getApplicationContext()); 
    } 
    else 
    { 
     Log.d("info", "already registered as" + regId); 
    } 
    Log.d("info", regId); 
    return regId; 
} 

これは私の問題を解決しました。:)