无需操作图标即可点击Android Wear通知

时间:2015-01-17 00:42:38

标签: android wear-os android-wear-notification

我正在从手表发送通知,我希望通知可以点击,即点击时会打开一个活动。这就是它的样子

notification http://max.macnn.com/article_images/1415020145-md-sonosandroidwearleaktb.jpg

但是,我不希望播放图标显示,只是希望看到普通的通知。即使我设置了一个空动作图标,仍然会占用图标空间,我无法将文本放入该空间。有没有办法释放图标空间以显示文字?

代码如下:

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));

2 个答案:

答案 0 :(得分:1)

setHintHideIcon(true)隐藏了图标。

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));

答案 1 :(得分:0)

要完成此操作,您必须创建一个自定义RemotViews对象,并通过以下方式将自定义布局传递给通知:

RemoteViews remoteView = new RemoteViews("PACKAGENAMEWHERELAYOUTEXISTS", R.layout.custom_layout);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                         .setContent(remoteView);

请参阅:

http://developer.android.com/reference/android/widget/RemoteViews.html#RemoteViews(java.lang.String,int)

用于远程视图。

和设置内容:

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContent(android.widget.RemoteViews)