Closed florianchevallier closed 4 years ago
Could you expand on what you mean by Strangely enough, it works well with FCM directly, using the GCM token from "Android Channel IDs"
? Are you using another library to receive events for those notifications?
How are you listening for the events? It would super helpful if you could provide a sample app that we can use to quickly reproduce the issue.
Hi, thank you for your response.
Here is the example project I'm currently using : https://github.com/florianchevallier/test-ionic-app-notif
You can see here how I did with Capacitor.
Could you expand on what you mean by Strangely enough, it works well with FCM directly, using the GCM token from "Android Channel IDs" ? Are you using another library to receive events for those notifications?
Yes, when I setup the app for UrbanAirship, I've used Firebase to get the the google-services.json
.
When I did my tests, a device was registered in UA. I got something like this :
I went to firebase, and sent a notification from the firebase console here, using the GCM token :
And got the notification in background.
The payload from firebase was like this :
{
"id": "0:1583243373187715%6e26ceee6e26ceee",
"data": {},
"title": "aze",
"body": "aze"
}
While the one from UA looks like this :
{
"id": "0:1583243590511608%6e26ceeef9fd7ecd",
"data": {
"com.urbanairship.push.ALERT": "Hello Android!",
"com.urbanairship.metadata": "eyJ2ZXJzaW9uX2lkIjoxLCJ0aW1lIjoxNTgzMjQzNTkwNDU4LCJwdXNoX2lkIjoiYWE4Y2Y2MmUtMDBiOC00ODA1LTk3NDctNmU4Y2JkMzUxYTM3IiwiY2FtcGFpZ25zIjp7ImNhdGVnb3JpZXMiOltdfX0=",
"com.urbanairship.push.PUSH_ID": "5186c9a6-5d56-11ea-a992-024229971edf",
"com.urbanairship.title": "Insert title here!",
"com.urbanairship.push.APID": "429489f9-11ac-4329-a94b-cd5f1a1a5857",
"com.urbanairship.push.CANONICAL_PUSH_ID": "aa8cf62e-00b8-4805-9747-6e8cbd351a37"
}
}
The notification is not displaying or is the app not able to get a callback when the push is received?
The notification is not displaying at all (with UA, but it's displaying when sent from the firebase console)
@florianchevallier Could you post your merged manifest from app/build/intermediates/merged_manifests/debug/AndroidManifest.xml ?
yes ! It looks like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rmm.test.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="28" />
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Camera, Photos, input file -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Geolocation API -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<!-- Network API -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Navigator.getUserMedia -->
<!-- Video -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Audio -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Required by older versions of Google Play services to create IID tokens -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:debuggable="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:testOnly="true"
android:theme="@style/AppTheme" >
<activity
android:name="com.rmm.test.app.MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="@string/title_activity_main"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBarLaunch" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/custom_url_scheme" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.rmm.test.app.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<meta-data
android:name="com.urbanairship.cordova.version"
android:value="10.1.0" />
<meta-data
android:name="com.urbanairship.autopilot"
android:value="com.urbanairship.cordova.CordovaAutopilot" />
<meta-data
android:name="com.urbanairship.webview.ENABLE_LOCAL_STORAGE"
android:value="true" />
<activity
android:name="com.urbanairship.cordova.CustomMessageActivity"
android:exported="false"
android:theme="@android:style/Theme.DeviceDefault.Light" >
<intent-filter>
<action android:name="com.urbanairship.VIEW_RICH_PUSH_MESSAGE" />
<data android:scheme="message" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.urbanairship.cordova.CustomMessageCenterActivity"
android:exported="false"
android:launchMode="singleTask"
android:theme="@android:style/Theme.DeviceDefault.Light" >
<intent-filter>
<action android:name="com.urbanairship.VIEW_RICH_PUSH_INBOX" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.getcapacitor.plugin.background.BackgroundTaskService"
android:exported="false" />
<receiver android:name="com.getcapacitor.plugin.notification.TimedNotificationPublisher" />
<receiver android:name="com.getcapacitor.plugin.notification.NotificationDismissReceiver" />
<meta-data
android:name="firebase_messaging_auto_init_enabled"
android:value="false" />
<service
android:name="com.getcapacitor.CapacitorFirebaseMessagingService"
android:stopWithTask="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service> <!-- Firebase checks permissions at runtime -->
<service android:name="com.urbanairship.push.fcm.AirshipFirebaseMessagingService" >
<intent-filter android:priority="-1" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!--
FirebaseMessagingService performs security checks at runtime,
but set to not exported to explicitly avoid allowing another app to call it.
-->
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:exported="false" >
<intent-filter android:priority="-500" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.google.firebase.components.ComponentDiscoveryService"
android:directBootAware="true"
android:exported="false" >
<meta-data
android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
<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" />
</intent-filter>
</receiver>
<activity
android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.urbanairship.iam.html.HtmlActivity"
android:exported="false"
android:theme="@style/UrbanAirship.InAppHtml.Activity" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<activity
android:name="com.urbanairship.iam.fullscreen.FullScreenActivity"
android:exported="false"
android:theme="@style/UrbanAirship.InAppFullscreen.Activity" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<activity
android:name="com.urbanairship.iam.modal.ModalActivity"
android:exported="false"
android:theme="@style/UrbanAirship.InAppModal.Activity" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<activity
android:name="com.urbanairship.push.NotificationProxyActivity"
android:exported="false"
android:taskAffinity="com.urbanairship.push.NotificationProxyActivity"
android:theme="@android:style/Theme.NoDisplay" />
<activity
android:name="com.urbanairship.messagecenter.MessageActivity"
android:exported="false" />
<activity
android:name="com.urbanairship.messagecenter.MessageCenterActivity"
android:exported="false"
android:label="@string/ua_message_center_title" />
<activity
android:name="com.urbanairship.util.HelperActivity"
android:exported="false"
android:theme="@style/UrbanAirship.HelperActivity" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<activity
android:name="com.urbanairship.google.PlayServicesErrorActivity"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<activity
android:name="com.urbanairship.actions.RateAppActivity"
android:exported="false"
android:theme="@style/UrbanAirship.RateAppActivity" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
<intent-filter>
<action android:name="com.urbanairship.actions.SHOW_RATE_APP_INTENT_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.urbanairship.ChannelCaptureActivity"
android:exported="false" >
<meta-data
android:name="com.urbanairship.push.iam.EXCLUDE_FROM_AUTO_SHOW"
android:value="true" />
</activity>
<service android:name="com.urbanairship.job.AirshipService" />
<receiver
android:name="com.urbanairship.location.LocationReceiver"
android:exported="false" />
<service
android:name="com.urbanairship.job.AndroidJobService"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name="com.urbanairship.push.NotificationProxyReceiver"
android:exported="false" >
<intent-filter android:priority="-999" >
<action android:name="com.urbanairship.push.OPENED" />
<category android:name="com.rmm.test.app" />
</intent-filter>
</receiver>
<receiver
android:name="com.urbanairship.locale.LocaleChangeReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
</receiver>
<provider
android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="com.rmm.test.app.urbanairship.provider"
android:exported="false" />
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="com.rmm.test.app.firebaseinitprovider"
android:exported="false"
android:initOrder="100" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
Looks like capacitor is preventing the Airship SDK from receiving any push events:
<service
android:name="com.getcapacitor.CapacitorFirebaseMessagingService"
android:stopWithTask="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service> <!-- Firebase checks permissions at runtime -->
<service android:name="com.urbanairship.push.fcm.AirshipFirebaseMessagingService" >
<intent-filter android:priority="-1" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Only the highest priority service is able to receive the com.google.firebase.MESSAGING_EVENT
. You can try adding our service to your manifest to make it higher priority, but it will prevent capacitor from being able to process the notification:
<service android:name="com.urbanairship.push.fcm.AirshipFirebaseMessagingService" >
<intent-filter android:priority="10" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
To keep both working, you will need to create your own messaging service that notifies both capacitor and the Airship SDK. Example:
package com.rmm.test.app;
import com.getcapacitor.CapacitorFirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.urbanairship.push.fcm.AirshipFirebaseIntegration;
public class PushService extends CapacitorFirebaseMessagingService {
@Override
public void onNewToken(String newToken) {
super.onNewToken(newToken);
AirshipFirebaseIntegration.processNewToken(getApplicationContext());
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
AirshipFirebaseIntegration.processMessageSync(getApplicationContext(), remoteMessage);
}
}
Then register that service:
<service android:name="com.rmm.test.app.PushService" >
<intent-filter android:priority="10" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Our SDK currently posts the notification if its in the foreground or background, so it's actually broken in both cases. That foreground event you are receiving is from the Capacitor listener not ours.
Hey, thank you for you complete answer.
It seems a LOT more complicated than what I've anticipated. Given that this file is handled by capacitor, it will likely change on each update / sync.
I'll open an issue in Capacitor to see if they can handle this case.
Thank you
Alright, it works for me. Thank you for your support.
The methods you are overriding are the Firebase service methods, so as long as capacitor does not mark them as final you should be fine. Its more of a firebase limitation than a capacitor issue. If you dont care about capacitor working with fcm, you could just remove the service using manifest merge tools - http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
hey @rlepinski !
After a year and a half, the API has changed and the code you sent is not working anymore
package rmm.transmitter.app;
import com.getcapacitor.CapacitorFirebaseMessagingService; // <--- this doesn't exist anymore
import com.google.firebase.messaging.RemoteMessage;
import com.urbanairship.push.fcm.AirshipFirebaseIntegration;
public class PushService extends CapacitorFirebaseMessagingService {
@Override
public void onNewToken(String newToken) {
super.onNewToken(newToken);
AirshipFirebaseIntegration.processNewToken(getApplicationContext());
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
AirshipFirebaseIntegration.processMessageSync(getApplicationContext(), remoteMessage);
}
}
Do you know how I could resolve this ?
Many thanks
For anyone (maybe me in the future) who needs the new PushService
, here it is (working with cordova 3 & firebase 21)
package rmm.transmitter.app;
import androidx.annotation.NonNull;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.urbanairship.push.fcm.AirshipFirebaseIntegration;
public class PushService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
AirshipFirebaseIntegration.processMessageSync(getApplicationContext(), remoteMessage);
}
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
AirshipFirebaseIntegration.processNewToken(getApplicationContext(), s);
}
}
In case this helps anyone in the future, I addressed this issue by ensuring that @capacitor/push-notifications
wasn't installed - only @ionic-native/urbanairship
.
❗For how-to inquiries involving Airship functionality or use cases, please contact (support)[https://support.airship.com/].
Preliminary Info
What Airship dependencies are you using?
"urbanairship-cordova": "^10.1.0" "@ionic-native/urbanairship": "^5.22.0", Capacitor on the master branch to be able to get Android X
What are the versions of any relevant development tools you are using?
Report
What unexpected behavior are you seeing?
Notifications works in foreground with iOS / Android Notifications works in bakcground with iOS Not on android
Strangely enough, it works well with FCM directly, using the GCM token from "Android Channel IDs"
What is the expected behavior?
Well I would be pleased if this would work on android as well
What are the steps to reproduce the unexpected behavior?
This issue : https://github.com/ionic-team/capacitor/issues/2511 sum ip all
here is the
POST
I'm doing with Postman :Do you have logging for the issue?
Here is the logcat I get when the app is in background :
Sometimes, this popup :
And, to compare, the one I get in foreground :
If you need more logs, I would gladly help.