user1354257
user1354257

Reputation: 51

Permission Denial: receiving Intent { act=com.google.android.c2dm.intent.REGISTRATION

I'm trying to implement push notifications in my app, but it seems that my C2DMReceiver is not working. I tried every solution I could find. Here is what I have:

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

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

<uses-permission android:name="com.my.app.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

<activity>....</activity>

<service android:name=".C2DMReceiver"/>
<receiver 
          android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
          android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        <category android:name="com.my.app"/>
    </intent-filter>
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
         <category android:name="com.my.app"/>
    </intent-filter>
 </receiver>

In my onCreate method I use: C2DMessaging.register(this, "[email protected]");

String id = C2DMessaging.getRegistrationId(this);

And id is always empty. Looking at the LogCat, I can see Permission Denial: receiving Intent { act=com.google.android.c2dm.intent.REGISTRATION So, what should I do?Thanks)

Upvotes: 1

Views: 5212

Answers (2)

Raul Rene
Raul Rene

Reputation: 10270

The android:name in your receiver has to specify the path to your class that implements the receiver. I am sure that your C2DMBroadcastReceiver class is not in the com.google.android.c2dm package, as I see below your are using a com.my.app package.

Create a C2DMBroadcastReceiver class in, for example, com.my.app.receiver and specify the receiver's adroid:name as:

<receiver 
      android:name="com.my.app.receiver.C2DMBroadcastReceiver"
      android:permission="com.google.android.c2dm.permission.SEND">
      ......
</receiver>

Upvotes: 1

Demonick
Demonick

Reputation: 2126

Change your android:name in your receiver tag from com.google.android.c2dm.C2DMBroadcastReceiver to com.my.app.YourReceiverClassName, and make sure your sender e-mail and server side login e-mail are the same.

Upvotes: 1

Related Questions