0

I'm trying to receive FCM notification on android wear emulator running on Android Oreo API 26.

I have properly registered the app on firebase, the firebase token is being printed on the log and the notification channel is also being created.

I'm using the firebase console to send the message, but it is not receiving on the wear. The console says 0 messages sent, 0 received. I'm sending the notification from the console under the same name, via the notification channel testing_channel.

Does it take time to receive on the wear?

Manifest declaration:

<service
        android:name=".Services.NotificationInstanceService"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

Service Class:

public class NotificationInstanceService extends FirebaseInstanceIdService{

    @Override
    public void onTokenRefresh() {

        String refreshedToken = FirebaseInstanceId.getInstance().getToken() ;
        Log.i("TAG", "onTokenRefresh: " + refreshedToken);

    }
}

AppController:

public class AppController extends Application{

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

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

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


            String id = "testing_channel";
            CharSequence name = "Testing";
            String description = "This channel is primarily for testing";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = null;
            mChannel = new NotificationChannel(id, name, importance);
            mChannel.setDescription(description);
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
            mNotificationManager.createNotificationChannel(mChannel);

            Log.i("TAG", "onCreate: NOTIFICATION CHANNEL CREATED" );

        }
    }
}
Abhinav Das
  • 306
  • 1
  • 4
  • 12
  • Hi. Do you have the code for the Notification Builder? I haven't tried it with Wearables before, but FCM says that Android devices (assumingly just for Smartphones), will handle the notification automatically, if you send a `notification`-*only* payload (which is the message type when you use the console), however, when I checked with [Wearables](https://developer.android.com/training/wearables/notifications/creating.html#expanded), it seems you still need to build the notification itself for it ti appear. – AL. Dec 05 '17 at 18:26
  • this one tells that I need not worry about any thing: https://firebase.google.com/docs/cloud-messaging/android/receive check the table. – Abhinav Das Dec 06 '17 at 06:25
  • Yeah. I'm quite familiar with the FCM docs, specially for Android. Like I mentioned, this is probably referring *only to Smartphone* clients/devices, *not wearables*. – AL. Dec 06 '17 at 08:41

2 Answers2

0

Its always advisable to test push notification on a real device. You can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications. Try compiling your Android project using a Google APIs target. I think is necessary for testing.

Durga M
  • 534
  • 5
  • 17
0

you should use the latest of AppCompat library currently 26.0.2

compile "com.android.support:appcompat-v7:26.0.+"

In Android O it's a must to use a channel with your Notification Builder

below is a sample code its works for me:

// Sets an ID for the notification, so it can be updated.

int notifyID = 1; String CHANNEL_ID = "my_channel_01";// The id of the channel.

NotificationCompat notification =
    new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!")
    .setChannelId(CHANNEL_ID).build();



NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
   mNotificationManager.createNotificationChannel(mChannel);
}

// Issue the notification.


 mNotificationManager.notify(notifyID , notification);

and use a "Google APIs" (any version) target to receive push notifications