首页 文章

Android穿不显示通知

提问于
浏览
3

我有问题 . 我的android服装模拟器没有显示通知 . 这是我的移动代码:

private void notifyToWear() {
        NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
                .setHintShowBackgroundOnly(true);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Request text")
                .setContentText("Speak something then your phone will search it.")
                .extend(wearableExtender);

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(0, notificationBuilder.build());
    }

我在MainActivity中单击按钮时调用它 . 在我的手机中它显示通知,但在Android服装模拟器不显示 . 注意:我已经连接android手机和android穿emualtor . 我在Android Wear App中测试了Card示例 . 它正在发挥作用 .

谢谢 .

  • 更新 - 代码执行点击按钮:
(findViewById(R.id.btn_request_text)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MyActivity.this, "Call request", Toast.LENGTH_SHORT).show();
                notifyToWear();
            }
        });

当我点击按钮Toast显示 .

---更新---我还在Wear Sample中运行了ElizaChat和RecipeAssistant . 但它也不起作用 .

3 回答

  • 1

    确保您已在设备上为Android Wear应用提供通知权限 .

    在4.4: Settings > Security > Notification Access
    在L预览中: Settings > Sound & Notifications > Notification Access

    在通知访问屏幕中,确保选中 Android Wear .

  • 0

    在Android 7上,转到:设置>应用>单击齿轮>特殊访问>通知访问> Android Wear>单击用于Tasker的开关 . 见截图 .
    enter image description here

  • 10

    试试这个:

    NotificationCompact.Builder notBuilder = 
                                       new NotificationCompact.Builder(this);
    notBuilder.setContentTitle("Title").setContentText("Text");
    WearableNotifications.Builder wearBuilder = 
                                     new WearableNotifications.Builder(notBuilder);
    Notification not = wearBuilder.build();
    
    NotificationManagerCompat manager = NotificationManagerCompat.from(this);
    manager.notify(0,not);
    

    我希望这能帮到您..

相关问题