First of all please don't make this question as duplicate or anything else because all other don't cover my issue.
I have an issue with push notification
. I have implemented push notification
in my app using gcm
and make a jar
with its source code. Now I have distributed it with my res
folder for integration. Its working fine if host app don't implement push notification
its own. If host app implement push notification
its own then my integrated app doesn't receive push.
I went through this post : Register GCM from a library project
I have used below addition in the app in which I have integrated my jar:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processor from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="HOST_APP_PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="HOST_APP_PACKAGE.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And below is my receiver:
<receiver android:name="MY_JAR_APP_PACKAGE.PushLibraryBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="HOST_APP_PACKAGE" /> </intent-filter> </receiver>
My PushLibraryBroadcastReceiver
class code in jar
:
public class PushLibraryBroadcastReceiver extends GCMBroadcastReceiver { /** * Gets the class name of the intent service that will handle GCM messages. */ @Override protected String getGCMIntentServiceClassName(Context context) { return "MY_JAR_APP_PACKAGE.GCMIntentService"; } }