2014-09-03 85 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