urbanairship / android-library

Urban Airship Android SDK
Other
112 stars 123 forks source link

Unable to access cloud messages in Urban Airship Receiver #25

Closed mangeshsambare closed 7 years ago

mangeshsambare commented 7 years ago

Hi, I have implemented two separate messaging services in my application. One is FCM service and second one is Urban Airship. I configured both receiver and service in my manifest file:

Manifest

<!--
          Defining firebase Services in applications
      -->
<service android:name="com.example.firebasemessaging.FCMMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <service android:name="com.example.firebasemessaging.FCMInstanceIdService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name="com.example.firebasemessaging.FCMRegistrationService"
            android:exported="false"></service>

<!--Urban airships-->
        <!--
                   Urban airship data call back
               -->
<meta-data
            android:name="com.urbanairship.autopilot"
            android:value="com.example.urbanairship.UrbanAutoPilot" />

        <receiver
            android:name="com.example.urbanairship.UrbanAirshipReceiver"
            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.example" />
            </intent-filter>
        </receiver>

Here is my UrbanAirshipReceiver code which consumes cloud message comes through Urban Airship :


public class UrbanAirshipReceiver extends AirshipReceiver
{
@Override
    protected boolean onNotificationOpened(@NonNull Context context, @NonNull NotificationInfo notificationInfo) {
        Logger.debug("onNotificationOpened() :: title : " + notificationInfo.getMessage());
}
}

Here is my FCMMessagingService code which consumes cloud message that comes through FCM :

public class FCMMessagingService extends FirebaseMessagingService 
{
@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
Logger.debug(onMessageReceived() :: Notification Message Body: " + remoteMessage);
}
}

I have sent data using urban-airship messaging service to device using token and application consumes data properly and gives me proper message(data) in my UrbanAirshipReceiver :

But in same case when I send message using FCM service, then my FCMMessagingService does not consume data. Before printing any log on monitor, it gives me following error

D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
I/FA: App measurement is starting up, version: 11020

And immediately after that it shows me following messages :

I/FirebaseInitProvider: FirebaseApp initialization successful
E/UALib: You can only call takeOff() once.
I/AppName - UALib: Airship taking off!
I/AppName - UALib: Airship log level: 3
I/AppName - UALib: UA Version: 8.8.4 / App key = ************* Production = false
I/FA: Tag Manager is not found and thus will not be used
I/AppName - UALib: Received push: {gcm.notification.body=Test message, google.sent_time=******************, google.c.a.e=1, google.c.a.c_id=******************, google.c.a.udt=0, collapse_key=com.example, gcm.n.e=1, from=******************, google.c.a.ts=1506429158, gcm.notification.e=1, google.message_id=0:********************}
D/AppName - UALib: RichPushUser - Updating user.
D/AppName Channel ID: *********************8
D/AppName - UALib: Analytics - New session: **********************
E/SQLiteLog: (284) automatic index on triggers(t_s_id)
I/AppName - UALib: Airship ready!
D/AppName - UALib: Ignoring push: {gcm.notification.body=Test message, google.sent_time=*******, google.c.a.e=1, google.c.a.c_id=*******, google.c.a.udt=0, collapse_key=com.example, gcm.n.e=1, from=********, google.c.a.ts=********, gcm.notification.e=1, google.message_id=******}
D/AppName - UALib: EventApiClient - Sending analytics events. Request:  com.urbanairship.c.a@2c015cd8 Events: [{"event_id":"*******","time":"***","type":"app_background","data":{"connection_type":"******","session_id":"******************"}}]
D/AppName - UALib: EventApiClient - Analytics event response: Response: ResponseBody:  ResponseHeaders: {null=[HTTP/1.1 200 OK], Cache-Control=[max-age=0, no-cache, no-store], Connection=[keep-alive], Content-Type=[application/json], Date=[*****************], Expires=[*************], Pragma=[no-cache], Server=[nginx/1.6.2], Vary=[Accept-Encoding], X-Android-Received-Millis=[*************], X-Android-Response-Source=[NETWORK 200], X-Android-Sent-Millis=[************], X-UA-Max-Batch=[500], X-UA-Max-Total=[5120], X-UA-Max-Wait=[*************], X-UA-Min-Batch-Interval=[*********]} ResponseMessage: OK Status: 200
D/AppName - UALib: EventManager - Analytic events uploaded.

Here is my code to create notification. I used my own icon for notification :

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application); 
NotificationManager notificationManager = (NotificationManager) application.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(application.getResources(), R.drawable.ic_icon));
 notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setSmallIcon(R.drawable.ic_logo);

So after getting FCM message my application shows notifications on device status bar. But it shows different icon. It uses icon that is in FCM project. It does not show icon which I have set for NotificationBuilder class.

Related to that I have following question :

  1. Does UrabanAirshipReceiver consumes FCM messages?
  2. Why do I get these two separate notification in log. One is Received push and Second one is Ignoring push?
  3. Currently Received push and Ignoring push is printed on log but is not accessible to developer. It is not going into UrabanAirshipReceiver class, So how can I access this data?
rlepinski commented 7 years ago

@mangeshsambare Urban Airship uses FCM/GCM to deliver the messages to the device. FCM will generally also process that data, but you need to have it configured properly uses FCM's instructions.

Urban Airship will ignore any FCM/GCM messages that are delivered with the same sender ID if it does not contain any UA keys in the payload.

So, to answer your questions:

  1. No, unless it uses the same sender ID and contains an UA key com.urbanairship.*
  2. Received push is called because UA received a message for UA's sender ID. We then ignore it because it does not contain a UA key, so it was sent outside of UA and should be ignored.
  3. Our framework only processes messages for UA to avoid handling non ua messages.

Also you mentioned that you are unable to customize push notifications. Take a look at https://docs.urbanairship.com/platform/android/#customizing-push-notifications

If you need anymore help please contact support.