穿戴式OS通知振动和声音

时间:2018-08-17 17:29:39

标签: android android-wear-2.0 android-wear-notification

在我的前台服务中,我收到通知,并且工作正常。唯一的问题是,当我收到通知时,手表不会振动或发出任何声音。我尝试在NotificationChannelNotification上设置振动,但均无效。设备是华为手表2。

NotificationsChannels:

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"/>

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题,并观察了模型。测试通知时,请将手表戴在身上而不要用电缆将其连接到计算机。它对我有用。