我正在使用FCM进行推送通知,它可以与棒棒糖前设备配合使用,但不会在棒棒糖中获取通知。
这是我的代码。
(Manifest)服务: -
<service android:name=".fcmlistenerservices.MyInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".fcmlistenerservices.MyFcmListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
这是显示通知的服务:
public class MyFcmListenerService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage message){
String from = message.getFrom();
Map data = message.getData();
Log.d("MyTag", "From: " + from);
Log.d("MyTag", "Notification Message Body: " + data.get(""));
//logic to display notification
//Toast.makeText(MyFcmListenerService.this,""+message.getData(),Toast.LENGTH_LONG).show();
Log.d("Firebase : ", "Notification from firebase: "+data.get("message"));
sendNotification((String) data.get("message"));
}
}