蓝牙发送多个文件

之前用流的方式和contentProvide的方式发图片。结果流的方式在接收端出来的图片有问题,而contentProvide方式由于BluetoothShare 类不支持 android 4.1 及以上,所以放弃了。

现在改用以下方法:

            ArrayList<Uri> a = new ArrayList<Uri>();

            for (int i = 0; i < list.size(); i++) {

                   a.add(Uri.fromFile(new File(list.get(i))));

            }

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND_MULTIPLE);
            intent.setComponent(new ComponentName(
            "com.android.bluetooth",
            "com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
            intent.setType("*/*");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, a);

            startActivity(Intent.createChooser(intent, "发送图片"));



求助:两个蓝牙设备连接上后,用流的方式传输文件,结果失败了。

到处寻求助攻无果。不知道是编码模式有问题,还是流处理有问题。如果有了解人士,求指导,发送端代码如下:

is = new FileInputStream(path);
byte[] b = new byte[1024];
int len=0;
len = is.read(b);
while(len!=-1){
BoothService.write(b);
Thread.sleep(100);
len = is.read(b);
}

接收端代码如下,msg.obj是接收到的数组,发送文本完全没问题:

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(str+"/"+systemTime+".jpg")));

byte[] readBuf = (byte[]) msg.obj;

bos.write(readBuf );


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值