我正在制作一个Android应用程序,我们在其中与arduino进行通信,但问题是,当我向蓝牙模块发送字符时它显示一个意图对话框选择选项当我选择蓝牙时它只搜索移动设备而不是蓝牙模块? ??
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"b");
intent.setType("text/plain");
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);
}
}
答案 0 :(得分:0)
您需要创建一个RFCOMM连接并写入outstream而不是使用intent。
了解更多详情:
http://developer.android.com/guide/topics/connectivity/bluetooth.html