我用 1 个按钮创建了一个新的 android 应用程序。
我将我的设备(Galaxy S android 12)连接到 Galaxy Watch 4,并尝试从我的应用程序获取桥接通知到手表。
onClick()
按钮启动此代码(来自 Google 磨损通知示例):
String channelId = "channel";
CharSequence channelName = "channelName";
String channelDescription = "Channel desc";
int channelImportance = android.app.NotificationManager.IMPORTANCE_MAX;
boolean channelEnableVibrate = true;
int channelLockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC;
NotificationChannel notificationChannel =
new NotificationChannel(channelId, channelName, channelImportance);
notificationChannel.setDescription(channelDescription);
notificationChannel.enableVibration(channelEnableVibrate);
notificationChannel.setLockscreenVisibility(channelLockscreenVisibility);
android.app.NotificationManager notificationManager =
(android.app.NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
.bigText("A")
.setBigContentTitle("B")
.setSummaryText("C");
Intent notifyIntent = new Intent(this, XXX.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent notifyPendingIntent =
PendingIntent.getActivity(
this,
0,
notifyIntent,
PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder notificationCompatBuilder =
new NotificationCompat.Builder(
this, channelId);
Notification notification = notificationCompatBuilder
.setStyle(bigTextStyle)
.setCustomHeadsUpContentView(notificationCompatBuilder.createHeadsUpContentView())
.setContentTitle("A")
.setContentText("B")
.setSmallIcon(R.drawable.ic_my_app)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_my_app))
.setContentIntent(notifyPendingIntent)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setLocalOnly(false)
.setOngoing(false)
.setCategory(Notification.CATEGORY_ALARM)
.extend(new NotificationCompat.WearableExtender()
.setContentIcon(R.drawable.ic_my_app).setBackground(
BitmapFactory.decodeResource(
getResources(),
R.drawable.ic_my_app)
).setDisplayIntent(notifyPendingIntent))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();
notificationManager.notify(1, notification);
// OR
NotificationManagerCompat.from(this).notify(1, notification);
我完美地收到了通知。
但是当我将我的应用程序设置为默认拨号器时,桥接通知不会到达手表。我尝试使用三星默认拨号器(com.samsung.android.dialer)并且一切正常。