【问题标题】:Android Wear Emulator Oreo FCM Messages not received未收到 Android Wear 模拟器 Oreo FCM 消息
【发布时间】: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


【解决方案1】:

始终建议在真实设备上测试推送通知。 如果模拟器目标使用 Google API 版本来接收推送通知,您可以在模拟器上测试推送通知。尝试使用 Google API 目标编译您的 Android 项目。我认为有必要进行测试。

【讨论】:

  • 模拟器支持 google play 并与 google play 帐户相关联,如果这是您的要求。
【解决方案2】:

您应该使用当前 26.0.2 的最新 AppCompat 库

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

在 Android O 中,必须在通知生成器中使用通道

下面是一个对我有用的示例代码:

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

int notifyID = 1; String CHANNEL_ID = "my_channel_01";// 频道ID。

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);

并使用“Google API”(任何版本)目标来接收推送通知

【讨论】:

  • 确保您在模拟器中使用带有 Google API 的目标
  • 以 Google API 为目标。
猜你喜欢
  • 1970-01-01
  • 2021-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-14
  • 2016-07-21
相关资源
最近更新 更多