我正在尝试在 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);
}
}
应用控制器:
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" );
}
}
}