我正在尝试在Android Oreo API 26上运行的android Wear模拟器上接收FCM通知 .
我已在firebase上正确注册了应用程序,firebase令牌正在日志上打印,并且还正在创建通知通道 .
我'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通过通知渠道 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" );
}
}
}
2 回答
始终建议在真实设备上测试推送通知 . 如果模拟器目标使用某种版本的Google API来接收推送通知,则可以在模拟器上测试推送通知 . 尝试使用Google API目标编译您的Android项目 . 我认为有必要进行测试 .
你应该使用最新的AppCompat库目前26.0.2
在Android O中,必须在Notification Builder中使用 Channels
下面是一个示例代码,它适用于我:
int notifyID = 1; String CHANNEL_ID =“my_channel_01”; // Channels 的ID .
并使用“Google API”(任何版本)目标来接收推送通知