如何使用蓝牙将字符发送到arduino

时间:2015-05-05 23:05:08

标签: java android bluetooth arduino

我正在开发一个项目,当我发送图像发送成功时,我发送字符串到蓝牙模块有问题但是当我发送字符串没有显示蓝牙选项显示gmail共享它和谷歌驱动器

这是我的Java代码:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("plain/text");
//intent.setType("image/*");
String content="b";
intent.putExtra(Intent.EXTRA_STREAM,content);
startActivity(intent);
PackageManager pm=getPackageManager();
List<ResolveInfo> appslist=pm.queryIntentActivities(intent,0);

if(appslist.size()>0){
    String packagename=null;
    String classname=null;
    boolean found=false;

    for(ResolveInfo info:appslist){
        packagename=info.activityInfo.packageName;
        if(packagename.equals("com.example.app")){
            classname=info.activityInfo.name;
            found=true;
            break;
        }
    }

    if(!found){
        showToast("Bluetooth havn't been found");
    }else{
        intent.setClassName(packagename,classname);
        startActivity(intent);
    }

}

1 个答案:

答案 0 :(得分:0)

在我的情况下,我使用此代码发送字符串....它适用于我

Button btn = (Button) findViewById(R.id.button1);

    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
            sendIntent.setType("text/plain");
            startActivity(sendIntent);

        }
    });

单击此按钮后打开一个带有多个选项的对话框,您可以选择蓝牙...谢谢