簡體   English   中英

Android穿不顯示通知

[英]Android wear not show notification

我有問題。 我的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。 但它也不起作用。

確保您已在設備上為Android Wear應用提供通知權限。

在4.4: 設置>安全性>通知訪問中
在L預覽中: 設置>聲音和通知>通知訪問

在通知訪問屏幕中,確保選中Android Wear

在Android 7上,轉到:設置>應用>單擊齒輪>特殊訪問>通知訪問> Android Wear>單擊用於Tasker的開關。 見截圖。 在此輸入圖像描述

嘗試這個:

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

我希望這能幫到您..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM