0

Well, I have followed this tutorial and created two services to get the message and the token:

public class MyAndroidFirebaseMessagingService extends FirebaseInstanceIdService {

    private static final String TAG = "MyAndroidFCMIIDService";

    @Override
    public void onCreate() {
        super.onCreate();
        onTokenRefresh();
    }

    @Override
    public void onTokenRefresh() {
        //Get hold of the registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        //Log the token
        Log.d(TAG, "Refreshed token: " + refreshedToken);
    }
}

public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
    private static final String TAG = "MyAndroidFCMService";

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        //Log data to Log Cat
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
        //create notification
        createNotification(remoteMessage.getNotification().getBody());
    }

    private void createNotification( String messageBody) {
        Intent intent = new Intent( this , MainActivity. class );
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent resultIntent = PendingIntent.getActivity( this , 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

        Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
                .setSmallIcon(R.drawable.ic_add_circle_white_24dp)
                .setContentTitle("Android Tutorial Point FCM Tutorial")
                .setContentText(messageBody)
                .setAutoCancel( true )
                .setSound(notificationSoundURI)
                .setContentIntent(resultIntent);

        NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, mNotificationBuilder.build());
    }
}

I didn't succeed in getting the message and the service "MyAndroidFirebaseMsgService" is not being called. Neither is onMessageReceived method. But I can see the token of the device:

Log:

01-30 18:30:21.107 26743-26743/com.. D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.. cmp=com../com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }, ordered=true, receiver=com.google.firebase.iid.FirebaseInstanceIdReceiver@41d585d8

01-30 18:30:21.142 26743-26743/com.. D/ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.. (has extras) } packageName=com.. resultCode=-1 resultData=null resultExtras=null} 01-30 18:30:21.146 26743-26743/com.. D/ActivityThread: SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@41d023a0 className=com.tenderplan.tenderplan3.MyAndroidFirebaseMessagingService packageName=com.tenderplan.tenderplan3 intent=null}

01-30 18:30:21.175 26743-26750/com.. D/jdwp: --> RUNNING, SUSPENDED

01-30 18:30:24.125 26743-26750/com.. D/jdwp: --> RUNNING, SUSPENDED 01-30 18:30:24.643 26743-26743/com.. D/MyAndroidFCMIIDService: Refreshed token: dpqrYOTBUko:APA91bHIq5pMfLpJPFhepM5nvTANT4dH5AIZ9Y2bgy75sYNOemHA4L_mskTCcw-sIZg5hJOrZQVlfNVJFTuGNqL-7KceuY18dI4roP9lZr3Gsz7OdM6S7J0UZLBTxp0z0xh72BPPvt4e

01-30 18:30:24.646 26743-26743/com.. D/ActivityThread: SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@41d023a0 className=com.t..MyAndroidFirebaseMessagingService packageName=com.. intent=null}

01-30 18:30:24.648 26743-26743/com.. D/ActivityThread: SVC-Calling onStartCommand: com..MyAndroidFirebaseMessagingService@4202df38, flags=0, startId=1

01-30 18:30:24.654 26743-26743/com.. D/ActivityThread: SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@41d023a0 startId=1 args=Intent { act=com.google.firebase.MESSAGING_EVENT pkg=com.. cmp=com../.MyAndroidFirebaseMessagingService (has extras) }}

01-30 18:30:24.656 26743-26743/com.. D/ActivityThread: SVC-Destroying service: com.t.MyAndroidFirebaseMessagingService@4202df38

01-30 18:30:24.658 26743-26750/com.. D/jdwp: --> RUNNING, SUSPENDED

01-30 18:30:25.172 26743-26743/com.. D/ActivityThread: SVC-STOP_SERVICE handled : 0 / android.os.BinderProxy@41d023a0

So I can't guess what is wrong when I am sending the message from the console. Please,can you give me some advices?

My manifest file:

 <service
        android:exported="false"
        android:name=".MyAndroidFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    <service
        android:exported="false"
        android:name=".MyAndroidFirebaseMsgService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
AL.
  • 33,241
  • 9
  • 119
  • 257
Lisa Semyonova
  • 117
  • 1
  • 12

0 Answers0