IntentReceiver leak error when calling GCMRegistrar.register ()

I am trying to complete the steps I started with Google GCM from the Google Android Developer site.

When my device tries to register, it does not work for the following reason:

Activity leaked from IntentReceiver from com.google.android.gcm.GCMBroadcastReceiver, which was originally registered here. Are you missing an unregisterReceiver call?

This is the code:

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");
}

Any idea?

What am I doing wrong?

Update

This is my manifest:

<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>
+5
source share
4 answers

Finally, it works.

All I have to do is call GCMRegistrar.onDestroy(this)in the method onDestroy()in the same Context that I callGCMRegistrar.register()

: IntentReceiver Google

:)

+12

, :

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;
}

.:)

+2

, . , :

<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

:

<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

All Articles