I'm trying to implement two 3rd party libraries (Parse & Localytics) which uses GCM push notifications but I can't seem to get both to work together. It's either one or the other that will work.
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<receiver android:name="com.localytics.android.PushReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
GCM only is aware of your app, not the content of the GCM payload.
You need a common receiver that can parse the intent received for the particular data that identifies it as Localytics or Parse, then forward that intent to the appropriate receiver for either service.
GCM is based on "app registration" not on "app feature registration" - it will deliver to your app, not a particular receiver within your app.
Related
In my AndroidManifest.xml, I added an intent-filter to my receiver so that my notifications are still being sent even if the user reboots/restarts their device.
<receiver
android:name="NotificationAlarmReceiver"
android:directBootAware="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
This works, but my problem is once the device has been rebooted/restarted, it immediately sends the notification regardless of the hour and minute that were set for the notifications.
I don't want my notifications to be immediately sent. I want them to be activated again since a reboot/restart deletes all notifications that were setup on the user's device and only send notifications at the hour and minute that they were set to. How do I do that?
Like to confirm if we can set android:exported="false" for instance id service and messaging service.
I tested by keeping android:exported="false" and notifications are working fine.
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
The firebase-messaging library exports an unspecialized FirebaseMessagingService of its own with low priority (-500). You can see it in your merged AndroidManifest.xml. This service can handle the push messages that carry notifications, like the ones you can send through the Firebase console.
If your specialized service class isn't exported, then the system will route messages from the Google services package to this unspecialized service, and notifications will work fine.
But that means you wouldn't be able to, for example, perform other actions when receiving a message or process custom data payloads.
You should export the service to be sure it is handled by your class as specified by #guest
<service
android:name=".services.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
I just enabled Notification Access permission to my app. But the Notification Listener starts Only I restart the device.How can I enable the service once my app gets installed?
You have to register a receiver in your AndroidManifest.xml.
Like below (This is an example of the GCM listener for Google Cloud Messaging)
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
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" />
</intent-filter>
</receiver>
Let me know if you need more info. But I assume you know how this works since you seem to have implemented the
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
Can you share you AndroidManifest.xml?
My team is building an Android SDK which should receive GCM push messages independently, regardless of pushes sent to the enclosing app.
After some trouble getting pushes, we were advised to add <category android:name="com.xxxx" /> to the intent-filter if the Manifest.
<receiver
android:name=".xxxxx"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.xxxx" />
</intent-filter>
</receiver>
What should be the value of category android? The SDK package, or the app package?
Is there an action inside of intent-filter of a broadcast reciever which can catch device incoming notifications (not only push but all notifications)?
for example:
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
for reading phone state, is there one for when a notification have arrived?
If you are using GCM:
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>