【问题标题】:Can we do a custom layout for notification on android wear project我们可以为 android wear 项目的通知自定义布局吗
【发布时间】:2014-07-24 20:22:01
【问题描述】:

我已经为 android 穿戴设备创建了一个项目。 我需要自定义可穿戴设备上的通知样式。有什么办法吗。

我的方法是

Intent displayIntent = new Intent(getApplicationContext(), CustomNotification.class);
 PendingIntent displayPendingIntent = PendingIntent.getActivity(getApplicationContext(),
         0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification =
            new NotificationCompat.Builder(context)
                    .extend(new WearableExtender()
                            .setDisplayIntent(displayPendingIntent))
                            .build();

    int notificationId = 001;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    notificationManager.notify(notificationId , notification);

但我没有收到通知。

有什么方法可以自定义我的自定义布局设计吗?

这是清单部分

 <activity android:name="com.client.android.CustomNotification"
     android:exported="true"
     android:allowEmbedded="true"
     android:taskAffinity=""
     android:theme="@android:style/Theme.DeviceDefault.Light" />

【问题讨论】:

    标签: android notifications android-notifications wear-os


    【解决方案1】:

    请查看有关在 Android Wear 上创建自定义通知的官方文档。

    使用大视图:

    您可以将样式应用于通知,例如BigPictureStyle、BigTextStyle 或InboxStyle。

    这里是一个使用BigTextStyle的例子:

    // Specify the 'big view' content to display the long
    // event description that may not fit the normal content text.
    BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    bigStyle.bigText(eventDescription);
    
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_event)
        .setLargeIcon(BitmapFractory.decodeResource(getResources(), R.drawable.notif_background))
        .setContentTitle(eventTitle)
        .setContentText(eventLocation)
        .setContentIntent(viewPendingIntent)
        .addAction(R.drawable.ic_map, getString(R.string.map), mapPendingIntent)
        .setStyle(bigStyle);
    

    更多信息:
    http://developer.android.com/training/wearables/notifications/creating.html#BigView

    使用自定义通知布局:

    您可以在 Activity 中创建一个布局并将其嵌入到您的通知中: https://developer.android.com/training/wearables/apps/layouts.html#CustomNotifications

    注意:请注意,此方法有一些限制,仅适用于直接从 Android Wear 设备(而非手机)提交的通知。

    还请阅读该教程末尾的注释:

    注意:当通知在主屏幕上窥视时,系统会以标准模板显示它,该模板从 通知的语义数据。该模板适用于所有 表盘。当用户向上滑动通知时,他们会看到 通知的自定义活动。

    【讨论】:

    • 我尝试了那里描述的方法,但它没有给出结果。
    • 看来你实现了一些不正确的东西:) 也许你会发布一些代码?
    • 我已经实现了,他们在第 4 步中告诉的是构建一个通知并调用 setDisplayIntent(),这用于当用户在穿戴设备上滑动通知时打开一个视图。
    • ...你的结果是什么?在您的原始代码中,您没有在任何地方设置setDisplayIntent。请将相关代码更新为新代码。同时发布声明Activity的清单。
    • 没有。不是此刻。也许下一个版本的 API 会添加类似的东西……也许不会……谁知道呢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    相关资源
    最近更新 更多