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

问题描述 投票:1回答:2

我正在从手表发送通知,我希望该通知是可单击的,即,单击该通知会打开一个活动。看起来像这样]

notification(来源: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));
android wear-os android-wear-notification
2个回答
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));

0
投票

为了实现这一点,您将必须创建一个Custom 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)

© www.soinside.com 2019 - 2024. All rights reserved.