我正在从手表发送通知,我希望该通知是可单击的,即,单击该通知会打开一个活动。看起来像这样]
(来源:macnn.com)
但是,我不想显示播放图标,只希望显示普通的通知。即使我设置了一个空的动作图标,图标空间仍然被占用,并且我无法在该空间中放置文本。有没有办法释放图标空间以显示文本?
代码如下:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Tracking")
.setContentText("Tap to open.")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launchbg))
.setLocalOnly(true)
.addAction(R.drawable.empty_icon, "blah", pendingSaveIntent)
.extend(new NotificationCompat.WearableExtender()
.setContentAction(0));
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Tracking")
.setContentText("Tap to open.")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launchbg))
.setLocalOnly(true)
.addAction(R.drawable.empty_icon, "blah", pendingSaveIntent)
.extend(new NotificationCompat.WearableExtender()
.setHintHideIcon(true)
.setContentAction(0));
为了实现这一点,您将必须创建一个Custom RemotViews对象,并通过以下方式将自定义布局传递给通知:
RemoteViews remoteView = new RemoteViews("PACKAGENAMEWHERELAYOUTEXISTS", R.layout.custom_layout);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContent(remoteView);
见:
用于远程视图。
和用于设置内容: