首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我在通知中创建了页面,代码没有显示错误,而是显示在磨损中,没有显示任何页面。

我在通知中创建了页面,代码没有显示错误,而是显示在磨损中,没有显示任何页面。
EN

Stack Overflow用户
提问于 2014-03-22 10:37:10
回答 1查看 243关注 0票数 0

我在通知中创建了页面,代码没有显示错误,而是在磨损中,没有显示任何页面。下面是代码:

代码语言:javascript
复制
    int notificationId = 001;
    // Build intent for notification content
    Intent viewIntent = new Intent(this, MainActivity.class); 
    viewIntent.putExtra("Helllo", "Hello Wear !");
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) 
            .setContentTitle("My App") 
            .setContentText("Hello Wear !")
            .setContentIntent(viewPendingIntent);

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

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
    if (savedInstanceState == null) { 
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();


            // Create builder for the main notification
        NotificationCompat.Builder notificationCompatBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Page 1")
                .setContentText("Short message")
                .setContentIntent(viewPendingIntent);

        // Create a big text style for the second page
        BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
        secondPageStyle.setBigContentTitle("Page 2")
                       .bigText("A lot of text...");

        // Create second page notification
        Notification secondPageNotification =
                new NotificationCompat.Builder(this)
                .setStyle(secondPageStyle)
                .build();

        // Create main notification and add the second page
        Notification twoPageNotification =
                new WearableNotifications.Builder(notificationBuilder)
                .addPage(secondPageNotification)
                .build();

代码现在显示错误,运行良好,但只显示一个页面,而不是两个页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-23 03:22:18

你收到的单页通知是否显示了“我的应用程序”/“你好!"?

这是合乎逻辑的,因为您正在构建此通知(var notificationBuilder)并实际显示它(notificationManager.notify())。

对于两页通知,您将创建第一页和第二页,但是当将第一页和第二页合并到twoPageNotification中时,您将对第一页使用notificationBuilder而不是notificationCompatBuilder

此外,构建的、两页的通知twoPageNotification从未传递给notify()函数。因此,添加一个notificationManager.notify(notificationId,twoPageNotification)应该显示这两个页面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22576474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档