Android wear not show notification

一世执手 提交于 2019-11-28 05:32:32

问题


I've probblem. My android wear emulator not show notification. Here is my code for mobile:

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

I call it when button in MainActivity click. In my phone it show notification but in android wear emulator not show. Notes: + I've connected between android phone & android wear emualtor. I tested with Card Example in Android Wear App. It's working.

Thanks.

-- Update -- Code perform click button:

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

When I click to button Toast is show.

--- Update --- I also run ElizaChat & RecipeAssistant in Wear Sample. But it not working too.


回答1:


Make sure that you have given the Android Wear app on your device access to notifications.

In 4.4: Settings > Security > Notification Access
In L Preview: Settings > Sound & Notifications > Notification Access

Within the Notification access screen, make sure that Android Wear is checked.




回答2:


On Android 7, go to: Settings > Apps > click cogwheel > Special Access > Notification access > Android Wear > click switch for Tasker. See screenshot.




回答3:


Try this:

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

I hope this will help you..



来源:https://stackoverflow.com/questions/25641967/android-wear-not-show-notification

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!