I'm using Firebase for receiving push notifications. My problem is that i want to make an option for users available, where they can disable these Notifications.
<application android:label="MyApp" android:theme="#android:style/Theme.NoTitleBar" android:icon="#drawable/ico_myapp_application">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" 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" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- END Manual Firebase Additions -->
</application>
Is there a way to prevent the app from register/creating the FirebaseMessagingService?
You could make options for users to Unsubscribe from your Firebase topic, they would stop getting the notifications. Unless if you are sending it directly to their ID.
FirebaseMessaging.getInstance().subscribeToTopic("news");
and then unsubscribe users
FirebaseMessaging.getInstance().unsubscribeFromTopic("news");
Related
In my android project I'm including Firebase Cloud Messaging. I'm on SDK 21 (Android 5).
My Intention is to override the onMessageReceived() method of MyFirebaseMessagingService to catch the method sent by Firebase and create my own notification.
But it seems like onMessageReceived doesn't get called anyway. I followed the built-in instructions from Android Studio to implement firebase and testing with the firebase console does actually send a message received by my test devices.
So my question is, did I forgot to implement something? I have my custom FirebaseMessagingService, a BroadcastReceiver to implement actions in notifications and an Applicationclass that creates and handles the notification channels for SDKs >= 26.
This is a part of my manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".Networking.Firebase.FireBaseApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activities.MainActivity"/>
<activity
android:name=".Activities.SplashActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".Networking.Firebase.PushMessageService" />
<receiver android:name=".Networking.Firebase.PushReceiver"/>
</application>
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage?) {
super.onMessageReceived(message)
//TODO Your Code
}
}
}
<!-- Firebase Notifications Service -->
<service
android:name=".MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!--
Set custom default icon. This is used when no icon is set for incoming notification messages.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_notification" />
<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
You need two service extends
1. FirebaseMessagingService
2. FirebaseInstanceIdService
and in manifest
<service
android:name="yourClassExtendsFirebaseMessagingService"
android:enabled="true"
android:exported="true"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name="yourClassExtendsFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
FirebaseInstanceIdService needs to refresh token.
On Android O and above need to ask premisen run an app when it closes on some devices.
I am using mixpanel in my app and I am getting 2 notifications from mixpanel. I am already using gcm on my device for chat. How can I receive both mixpanel and my notifications. BTW I generate GCM reg_id via code.
Manifest file:
<receiver
android:name=".gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter android:priority="100">
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name=“com.example.Mainactivity.gcm" />
</intent-filter>
</receiver>
<receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
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.example.Mainactivity.gcm" />
</intent-filter>
</receiver>
<service android:name=".gcm.GcmIntentService" />
I have added :
mixpanel.registerSuperProperties(props);
mixpanel.identify(id);
mixpanel.getPeople().identify(id);
mixpanel.getPeople().setPushRegistrationId(reg_id);
mixpanel.getPeople().initPushHandling(SENDER_ID);
in my GcmBroadcastReceiver I have added:
if (intent.getExtras().containsKey("mp_message")) {
String mp_message=intent.getExtras().getString("mp_message");
}
Check if you have added same device token in multiple people's property (comma separated)
As you are saying you implemented GCM before and you integrated Mixpanel afterwards. In that case you should remove the Mixpanel GCMReceiver tag as mentioned in the official documentation:
If you are handling registration and receiving notifications yourself,
you shouldn't include the Mixpanel GCMReceiver tag in your
AndroidManifest.xml file.
https://mixpanel.com/help/reference/android-push-notifications
I'm facing few problems since I started using Parse Push for android.
1. I'm unable to send notifications when the app is not running in the background.
2. The app force closes when it's not running in the background and I send a push notification.
3. The app force closes when I click on the push received.
Android Manifest
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.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="cn.loptest" />
</intent-filter>
</receiver>
Main Activity onCreate code
Parse.initialize(this, "********", "*******");
ParseInstallation.getCurrentInstallation().saveInBackground();
If I use PushService.setDefaultPushCallback with the above code I always get a "Connot Resolve Method"
TIA
I have the below things in the AndroidManifest. I need to send push notifications from both my webservice and Parse. The problem is that if I run the app as is below, the pushes from my WS (webservice) will go through, but the ones from Parse won't.
If I comment out the GCM part, Parse will work.
I've also noticed that in the Parse table, when both are enabled, under the deviceToken column, Parse will add a |ID||1| prefix to the deviceToken. If I comment out the GCM part, Parse won't put that prefix to the deviceToken. I'm not sure if that matters ...
Any ideas what I am doing wrong? I need to support both functionalities, but it seems something conflicts with something else. Any ideas?
If you need more source code, let me know please ...
<!-- ================================= GCM ================================= -->
<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" />
<category android:name="com.moc.sif" />
</intent-filter>
</receiver>
<service
android:name=".pushnotif.gcm.GCMListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".pushnotif.gcm.GCMInstanceIdListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".pushnotif.gcm.GCMRegistrationIntentService"
android:exported="false">
</service>
<!-- ================================= PARSE ================================= -->
<service android:name="com.parse.PushService" />
<receiver
android:name=".pushnotif.parse.receivers.ParsePushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.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.moc.sif" />
</intent-filter>
</receiver>
This should be fixed by Parse team. In my case unfortunetly the other 3rd library also getting token and there is no way to fix it. Parse also blocks "deviceToken" field so I cant event update it to correct one.
It seems I've fixed it.
The problem was that initializing Parse and afterwards I was calling this method:
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String token = instanceID.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
which apparently made Parse override the deviceToken in the table. I was using the above token to send to my webservice. What I did to solve it was to comment out the above two lines and use the deviceToken generated by Parse instead. So both Parse and my webservice are receiving the same deviceToken obtained from the Parse library. And both work now ...
I have a simple project that use my gcm provider and also I want to implement parse library to send push for all user. But I have an issue about that situation. When I register the gcm with my GCMSenderID, I get the registrationID and then Parse register the gcm with its default GCMSenderID(1076345567071). Then I realized that the regID that get from my gcm provider has written the parse push table as deviceToken. For this reason I think, I cannot send push message to all devices with parse.
I use parse quickstart implementation also make some research from parse.com/docs/push_guide#top/Android.
How can I resolve this conflict?
Here is my implementation:
AndroidManifest.xml
<service android:name="com.parse.PushService" />
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/icon" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<receiver
android:name=".gcm.GcmBroadcastReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="xxx.android" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.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="xxxx.android" />
</intent-filter>
</receiver>
<receiver
android:name=".gcm.ParseReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Application.java
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, ParseAPPLICATION_ID, ParseCLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
Parse uses its default sender id to request a GCM registration token: In particular, the SDK will automatically register your app for push at startup time using Parse's sender ID (1076345567071) and will store the resulting registration ID in the deviceToken field of the app's current ParseInstallation. (from parse.com/docs/push_guide#top/Android). So at startup 2 registrations for GCM tokens are requested, and my question is: how can I be sure which regToken Parse receives vs which regToken my GCM implementation/client receives? In theory they could get mixed up?
I fixed this issue with registering multiple senders by calling :
GoogleCloudMessaging.getInstance(this).register(YOUR_GCMSENDERID, PARSE_DEFAULT_GCM_SENDERID);
PARSE_DEFAULT_GCM_SENDERID = 1076345567071