2014-09-03 109 views
3

我有问题。我的android穿戴模拟器不显示通知。 这里是我的移动代码: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 wear emualtor。我使用Android Wear App中的卡片示例进行了测试。它正在工作。

谢谢。

- 更新 - 代码执行单击按钮:

(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是表演。

---更新--- 我也运行ElizaChat &食谱Assist in Wear Sample。 但它不工作。

+0

你可以发布按钮的代码?看看你如何调用这段代码? – Elior 2014-09-03 10:39:48

+0

我更新了问题。你能帮我吗 ? – quangson91 2014-09-03 10:44:12

+0

看到我的答案.. – Elior 2014-09-03 11:42:32

回答

10

确保你已经给到您的通知设备访问Android Wear应用。

在4.4:设置>安全>通知接入
输入L前瞻:设置>声音&通知>的通知接入

在该通知中访问屏幕,确保Android Wear检查。

+0

非常感谢! 我有问题,为什么android开发者页面没有注意到它。 :( – quangson91 2014-09-09 04:19:52

+0

WOW :)它真的是解决方案吗?为什么Android没有提到这个? – Elior 2014-09-13 19:27:27

+0

感谢兄弟,我为此感慨万分。 – 2016-06-11 11:25:35

0

试试这个:

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

我希望这将帮助你..

+1

它仍然无效:| – quangson91 2014-09-03 22:50:11

1

在Android 7上,转到:设置>应用程序>点击齿轮>特殊访问>通知访问> Android Wear>点击Tasker的开关。看截图。 enter image description here