【发布时间】:2017-12-05 11:41:34
【问题描述】:
我正在尝试在 Android Oreo API 26 上运行的 android wear 模拟器上接收 FCM 通知。
我已经在 firebase 上正确注册了应用程序,firebase 令牌正在打印在日志上,并且通知通道也在创建中。
我正在使用 firebase 控制台发送消息,但它没有在磨损时接收。控制台显示 0 条消息已发送,0 条已接收。我通过通知通道testing_channel 以相同的名称从控制台发送通知。
收到衣服需要时间吗?
清单声明:
<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>
服务类:
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" );
}
}
}
【问题讨论】:
-
嗨。你有通知生成器的代码吗?我之前没有在可穿戴设备上尝试过,但 FCM 表示,如果您发送
notification-only 有效负载(这是使用控制台时的消息类型),但是,当我检查 Wearables 时,似乎您仍然需要构建通知本身才能让它出现。 -
这个告诉我什么都不用担心:firebase.google.com/docs/cloud-messaging/android/receive查表。
-
是的。我对 FCM 文档非常熟悉,特别是对于 Android。就像我提到的,这可能是指仅指智能手机客户端/设备,不是可穿戴设备。
标签: android push-notification firebase-cloud-messaging wear-os notification-channel