调用系统蓝牙传送文件
调用系统蓝牙传送文件,用代码实现。。。。。
1. 先检查蓝牙是否能用:
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// 表明此手机不支持蓝牙
Toast.makeText(mContext, "蓝牙无法正常使用", Toast.LENGTH_SHORT).show();
return;
}
if (!mBluetoothAdapter.isEnabled()) { // 蓝牙未开启,则开启蓝牙
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
mContext.startActivity(enableIntent);
}
2. 建立文件集合对象 uris存放路径
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.fromFile(new File("/mnt/sdcard/123.mp3")));
uris.add(Uri.fromFile(new File("/mnt/sdcard/124.mp3")));
uris.add(Uri.fromFile(new
File("/mnt/sdcard/125.mp3")));
3、准备好前两项就可以使用啦
boolean multiple = uris.size() > 1;
Intent intent = new Intent(multiple ?
android.content.Intent.ACTION_SEND_MULTIPLE : android.content.Intent.ACTION_SEND);
if (multiple) {
intent.setType("audio/mp3");// 设置蓝牙传送类型
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent.setType("audio/mp3"); // 设置蓝牙传送类型
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
}
mContext.startActivity(intent);
到这里就准备足啦 运行代码 选择蓝牙就可以啦。
至于蓝色部分的含义自己去查吧
注意啊 蓝牙传输文件是有类型限制的,并不是所有的文件都能通过蓝牙传送。
蓝牙限制类型参考:http://blog.csdn.net/mylike_45/article/details/41787829

浙公网安备 33010602011771号