如何从手机应用程序向可穿戴设备发送通知?

bweufnob  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(142)

我有几个单选按钮上的电话应用程序选择,我想每个按钮的名称被发送到可穿戴设备。我该怎么做?我发现的大多数教程都有点混乱,而且使用的是贬低的方法。不过,我还在找,不过我想要一个简单的解释,剩下的我自己来想。

if (tool == 1) {
        switch (mode) {
            case 1:
                intentTool1mode1.putExtra("Type", typekey);
                intentTool1mode1.putExtra("KEY", KEy);
                intentTool1mode1.putExtra("Tool", getString(R.string.Tool1));
                intentTool1mode1.putExtra("Mood", getString(R.string.mode1));
                Toast.makeText(Setting.this,"Type: "+typekey+"\n"+"Key: "+KEy+"\n"+"Tool: "+"1"+"\n"+"Mode: "+"GoHome"+"\n", Toast.LENGTH_LONG).show();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        startActivity(intentTool1mode1);
                    }
                }, 5000);

这些是单选按钮选择的参数,当然下面还有其他参数,但这只是代码中的一个示例。在手机应用程序上开始我的活动之前,我先将它们显示为祝酒词。我要做的是获取toast消息中显示的相同值,并显示它们以及从手机应用程序发送到可穿戴设备的通知。
所以基本上我想要一个类似这样的通知:
配置

Tool : 1
mode : 3
Key : 60
type: 1

这应该出现在我的可穿戴设备上。然后我会相应地调整我的可穿戴设备上的应用程序。
这来自通知活动:

private void createNotificationChannel() {
        // Create the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String description = "Configurations made in the tool settings";

//            Urgent
//            Makes a sound and appears as a heads-up notification
            int importance = NotificationManager.IMPORTANCE_HIGH;

   //SYNTAX  NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID, channel_name, importance);
            channel.setDescription(description);

            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

这与上面第一个代码的活动相同:

private void sendOnChannel1(View v)
{
    android.app.Notification notification = new NotificationCompat.Builder(Setting.this, CHANNEL_ID)
            .setSmallIcon(R.drawable.bell)
            .setContentTitle("CONFIGURATIONS")
            .setContentText("SETTINGS CHOSEN FOR TOOL")
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText("Much longer text that cannot fit one line..."))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .build();

}

这一切都在电话那边。我的问题如下:
哪些需要调整,哪些缺少或需要添加?
如何复制要作为通知内容发送的配置
最后,可穿戴设备方面需要做些什么?
注:
第一个代码和第三个代码来自设置活动
第二个代码来自通知活动

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题