0

I have number of apps that uses GCM and I used same piece of code in every app. So I created on project witch gets gcm Notification. Now I mark that project as library project and using that project in my other project as android reference library project. and Inheriting the mainActivity of library project that do all the initialization of GCM. I also added the receiver and service entry and all Permissions in my Android manifest again.

but I am unable to register, I am getting this error as

Resetting backoff for 'Package Name'

when i set permission for my App package

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

If i set permission for library package

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

then runtime exception as

  IllegalStateException: Application does not define permission        com.example.helloworld.permission.C2D_MESSAGE

So my question is Do we able to create library project for GCM, Or I should use same method as previously copy paste my code in all my project which use push notification.

Thanks,

khurram
  • 1,362
  • 13
  • 24
  • Did you try to set `android:name="com.abc.notifylib.permission.C2D_MESSAGE"` in your TestApp? – busylee Jun 24 '14 at 12:08
  • yes I try with that also that time I am getting IllegalStateException: Application does not define permission com.example.helloworld.permission.C2D_MESSAGE – khurram Jun 24 '14 at 12:18
  • Do you add all needed permissions? Please check this answer http://stackoverflow.com/a/23215455/2156937 I think it is the same for your. – busylee Jun 24 '14 at 12:22
  • Yes I added that all permission in my test App – khurram Jun 24 '14 at 12:27

1 Answers1

0

You can absolutely create a library project for GCM.

You have to set permission in the app's manifest for the app's package.

<permission android:name="com.example.testapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.testapp.permission.C2D_MESSAGE" />

The broadcast receiver declaration in the app's manifest should also refer to the app's package in the intent filter's category :

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

            <category android:name="com.example.testapp" />
        </intent-filter>
    </receiver>

And if your broadcast receiver starts an intent service, make sure it looks for it in the correct package (i.e. the library's package and not in the app's package).

Eran
  • 387,369
  • 54
  • 702
  • 768