如何使用我的蓝牙应用程序向移动蓝牙设备和Arduino设备发送消息

时间:2015-07-31 06:14:03

标签: android eclipse bluetooth arduino

我已创建配对蓝牙设备的listView。我想向Arduino或其他蓝牙设备发送消息或命令,只需点击按钮"确定"。我发布了我的方法。请给我任何解决方案。

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            /*
             * TextView txt = (TextView) arg1;
             * Toast.makeText(MainActivity.this, "" +
             * txt.getText().toString(), 1000).show();
             */
            LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.prompts, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);
            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput = (EditText) promptsView
                    .findViewById(R.id.editTextDialogUserInput);

            alertDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    // get user input and set it to result
                                    // edit text
                                    // result.setText(userInput.getText());
                                    Toast.makeText(getApplicationContext(),
                                            "Action Found",
                                            Toast.LENGTH_LONG).show();

                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    dialog.cancel();
                                }
                            });
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();

        }

0 个答案:

没有答案