Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从手机应用程序向可穿戴设备发送通知?_Java_Android_Android Studio_Wear Os - Fatal编程技术网

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

Java 如何从手机应用程序向可穿戴设备发送通知?,java,android,android-studio,wear-os,Java,Android,Android Studio,Wear Os,我在手机应用程序中选择了几个单选按钮,我希望每个按钮的名称都能发送到可穿戴设备。我该怎么做?我发现的大多数教程都有点混乱,并且使用了贬低的方法。虽然我还在看,但我想要一个简单的解释,剩下的我自己来算 if (tool == 1) { switch (mode) { case 1: intentTool1mode1.putExtra("Type", typekey); int

我在手机应用程序中选择了几个单选按钮,我希望每个按钮的名称都能发送到可穿戴设备。我该怎么做?我发现的大多数教程都有点混乱,并且使用了贬低的方法。虽然我还在看,但我想要一个简单的解释,剩下的我自己来算

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

}
这一切都在电话方面。我的问题如下:

  • 哪些需要调整,哪些缺少或需要添加
  • 如何复制要作为通知内容发送的配置
  • 最后,在可穿戴设备方面需要做些什么
  • 注:

    • 第一个代码和第三个代码来自设置活动
    • 第二个代码来自通知活动