Push notification does not happening when app is not running - android - android

I am using Urban Airship for Push notification. Its works like a charm but just found that its did not sending push notification when application is not running.
How to handle this? I am sure its a common scenario and there will be a solution.
I checked many posts in stack overflow but most of them are for iOS. I want for Android
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
UAirship.takeOff(this, options);
Logger.logLevel = Log.VERBOSE;
PushManager.shared().setIntentReceiver(IntentReceiver.class);
PushManager.enablePush();
I have below code in Manifest Fie
<!-- REQUIRED for Urban Airship GCM-->
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver" 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" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.itest.guide.urbanairship" />
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service"/>
<service android:name="com.urbanairship.push.PushWorkerService" android:label="Push Notification Worker Service"/>
<service android:name="com.urbanairship.analytics.EventService" android:label="Event Service"/>
<!-- This is required for persisting preferences related to push and location -->
<provider android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="com.itest.mauritiustourguide.urbanairship.provider"
android:exported="false"
android:multiprocess="true" />
<!-- END OF REQUIRED ITEMS -->
<!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
<!-- Replace the receiver below with your package and class name -->
<receiver android:name="com.itest.guide.urbanairship.IntentReceiver" />

The reason may be because of the Broadcast receiver in manifest file. Are you sure you put it? The broadcast receiver wakes the application up, and notifies when there is a push.

It doesn't look like the line the category in the BroadcastReceiver intent filter matches your app package
<category android:name="com.itest.guide.urbanairship" />

Related

Where can I find Android Push Notification Settings in back4app

I'm trying to send a push notification to my app using Parse back{4}app by following this tutorial. But when I get to step 3, they say to edit android push notification settings in the dashboard, but I cannot find this option in my dashboard.
Another thing I didn't understand is the last part of step 1, changing the red code with my own. What am I supposed to change this to?
<category android:name="**dominwong4.scm.back4apppushnotificationcloudcode**" />
It's from from this code:
<!--
IMPORTANT: Change "YOUR_SENDER_ID" to your GCM Sender Id.
DON't DELETE the "id:"-->
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:966437188652" />
<service android:name="com.parse.PushService" />
<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="**dominwong4.scm.back4apppushnotificationcloudcode**" />
</intent-filter>
</receiver>
<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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
You change it to the package name of your application. There's a link at the top of that page to a github project.
If you look in there, you'd see code with
package dominwong4.scm.back4apppushnotificationcloudcode;
The instructions assume you've used a package name that identifies your own app when you created a project
Can't help with the dashboard... Haven't used Back4App
Regarding the push notification settings, after the changes to Back4App's site, it's located by following these steps:
After Login in your Back4App Account, click on "Features" below your AppName. Then you'll search for "Android Push notification" and click on "Server".
That should bring up the Push Notification settings for Android.
Checking the Online Chat is a great idea too, seems very useful.

Disabling FirebaseMessagingService programmatically

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");

Firebase Notification broke server notifications

I have made the switch from GCM to FCM in my android app. But I have not touched the server portion of the code since supposedly I don’t have to. But now, when server sends a notification, my device is no longer seeing it. So did I misunderstand the following?
https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints
Updating these endpoints is not strictly required, as Google will
continue to support the existing GCM endpoints.
MANIFEST
<!-- for notifications -->
<!--<uses-permission android:name="android.permission.WAKE_LOCK"/>-->
<!--<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>-->
<!--<uses-permission android:name="com.business.myapp.android.permission.C2D_MESSAGE"/>-->
…
<application …>
…
<!-- START GCM SECTION -->
<!--<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"/>-->
<!--<category android:name="com.business.myapp"/>-->
<!--</intent-filter>-->
<!--</receiver>-->
<service
android:name=".data.service.notification.BusinessGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".data.service.notification.BusinessInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service
android:name=".data.service.notification.RegistrationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<!-- END GCM SECTION -->
Note that when I send notification from the Firebase Console it comes through: if the app is in the foreground, it goes through onMessageReceived; otherwise, I just get a notification in status bar. Basically I follow the instructions on the link provided.
Here is onTokenRefresh
#Override
public void onTokenRefresh() {
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);//intent service to send token to my server
}
Do you change your json-service.json of on root /app of on application ?

mixpanel push notification is sending 2 notifications

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

Android Urban Airship 6.0.1, not able to intercept push notification actions

I am extending BaseIntentReceiver into a new class PushIntentReceiver, intended to take different actions from the key/value pairs within push notification objects.
Although my push notifications display correctly, PushIntentReceiver never gets called. Therefore clicking a notification seems to do nothing. Every method has a log tag inside of it, such as
#Override
protected void onBackgroundPushReceived(Context context, PushMessage message) {
Log.i(TAG, "Received background push message: " + message);
}
but none of this appears in LogCat. Whether it is the registration method, or the notification clicked method or anything. Similarly my breakpoints do not get hit in these functions.
Why is this? I’ve included the relevant parts of my AndroidManifest. The previous version of UrbanAirship that was in this app was the version where Amazon UA was split from Android UA when you guys first created the Amazon UA. So I don’t know if that was Android UA 5.0 or 4.x , but my Push Notification interception via BroadcastReceivers did work in that old version of the library. Now everything has been restructured to the UA 5.1.x+ ways and I can’t get it to work.
Insight appreciated
This is the relevant portion of my AndroidManifest.xml
<!-- REQUIRED for Urban Airship -->
<service
android:name="com.urbanairship.push.PushService"
android:label="Push Notification Service" />
<!-- Required for analytics -->
<service
android:name="com.urbanairship.analytics.EventService"
android:label="Event Service" />
<!-- Required for Actions -->
<service android:name="com.urbanairship.actions.ActionService" />
<!-- Required for Rich Push -->
<service android:name="com.urbanairship.richpush.RichPushUpdateService" />
<!-- OPTIONAL for Urban Airship Location (for segments support) -->
<service
android:name="com.urbanairship.location.LocationService"
android:label="Segments Service" />
<!-- This is required for persisting preferences related to push and location -->
<!-- MODIFICATION REQUIRED - Replace PACKAGE_NAME with your package name -->
<provider
android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="com.myapp.app.urbanairship.provider"
android:exported="true"
android:multiprocess="true"
android:permission="com.myapp.app.permission.UA_DATA" />
<!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
<!-- Replace the receiver below with your package and class name -->
<receiver
android:name="com.myapp.app.controllers.push.PushIntentReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.urbanairship.push.CHANNEL_UPDATED" />
<action android:name="com.urbanairship.push.OPENED" />
<action android:name="com.urbanairship.push.RECEIVED" />
<action android:name="com.urbanairship.push.DISMISSED" />
<category android:name="com.myapp.app" />
</intent-filter>
</receiver>
<receiver android:name="com.urbanairship.CoreReceiver"
android:exported="false">
<intent-filter android:priority="-999">
<action android:name="com.urbanairship.push.OPENED" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.myapp.app" />
</intent-filter>
</receiver>
<!-- REQUIRED for PlayServiceUtils.handleAnyPlayServicesError to handle Google Play Services recoverable errors. -->
<activity
android:name="com.urbanairship.google.PlayServicesErrorActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<!-- REQUIRED for GCM -->
<receiver
android:name="com.urbanairship.push.GCMPushReceiver"
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" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.myapp.app" />
</intent-filter>
</receiver>
<!-- end Urban Airship tags -->
Problems like these usually happen when the intent receiver extends the base intent receiver but overrides onReceive without calling through to super, the package name is messed up for the category, or the app does not declare and use the "PACKAGE_NAME.UA_DATA" permission. The SDK now automatically launches the application's launcher activity by default, but if that part is not working then you most likely need to declare the permission.
In the manifest section of the AndroidManifest.xml add:
<permission android:name="com.myapp.app.permission.UA_DATA" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.app.permission.UA_DATA" />

Categories

Resources