【发布时间】:2018-08-17 17:29:38
【问题描述】:
在我的前台服务中,我收到了通知,这一切正常。唯一的问题是,当我收到通知时,我的手表没有振动或发出任何声音。我尝试在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"/>
【问题讨论】:
标签: android android-wear-2.0 android-wear-notification