0

在我的前台服务中,我收到通知,这工作得很好。唯一的问题是我的手表在收到通知时不会振动或发出任何声音。NotificationChannel我尝试打开或打开振动,Notification但都不起作用。设备是华为手表 2。

通知渠道:

private void createNotificationChannels() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel serviceChannel = new NotificationChannel(
                CHANNEL_ID,
                "Service Channel",
                NotificationManager.IMPORTANCE_LOW
        );
        serviceChannel.setDescription("Foreground Service");

        NotificationChannel messageChannel= new NotificationChannel(
                message_CHANNEL_ID,
                "messages Channel",
                NotificationManager.IMPORTANCE_HIGH
        );
        messageChannel.setDescription("message Channel");
        messageChannel.enableVibration(true);
        messageChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        messageChannel.setVibrationPattern(new long[] {2000});


        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(serviceChannel);
        manager.createNotificationChannel(messageChannel);

    }

服务通知:

private void runNotification(Datamodel data)
{
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    Notification notification = new NotificationCompat.Builder(this, messageChannel)
            .setSmallIcon(R.drawable.alarm)
            .setContentTitle(data.getline1())
            .setContentText(data.getline2())
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(Html.fromHtml(data.toString(), FROM_HTML_MODE_COMPACT)))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setColor(Color.parseColor("#009999"))
            //.setSound(defaultSoundUri)
            //.setCategory(NotificationCompat.CATEGORY_ALARM)
            //.setVibrate(new long[]{2000})
            .build();

    notificationManager.notify(NOTIFICATION_ID, notification);

    NOTIFICATION_ID++;

}

显现:

<uses-feature android:name="android.hardware.type.watch" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
4

1 回答 1

0

我有完全相同的问题和手表型号。测试通知时,请将手表戴在手腕上,而不是让它通过电缆连接到计算机。这个对我有用。

于 2018-09-19T16:26:59.730 回答