通过蓝牙发送多个文件 [英] Sending multiple files through Bluetooth

查看:195
本文介绍了通过蓝牙发送多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了您关于通过蓝牙发送文件的答案. (在2011年6月13日5:01回答)

I saw your answer about sending file through Bluetooth. (answered Jun 13 '11 at 5:01)

 Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg");
 i.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/file.jpg"));
 startActivity(Intent.createChooser(i, "Send Image"));

是的!有用.它将打开默认的蓝牙工具/窗口/对话框以发送文件.但是,请您教我如何发送更多文件?这是我的代码...

Yes! It works. It will open a default Bluetooth tool/window/dialog to send a file. But would you please teach me how to send more files? Here is my code...

 String xFile[3] = { "aa.txt", "bb.txt", "cc.txt" };

 Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain");

 for (int i = 0; i < 3; i ++) { 
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(xFile[i]))); 
    startActivity(intent); 
 }

它可以工作,但是它将打开默认的蓝牙工具/窗口/对话框3次! @@如果有10个文件,它将打开默认的蓝牙工具/窗口/对话框10次!

It works, but it will open the default Bluetooth tool/window/dialog for 3 times! @@ If there are 10 files, it will open the default Bluetooth tool/window/dialog 10 times!!

我可以一次打开默认的蓝牙工具/窗口/对话框,然后发送所有文件吗?

May I know how to open the default Bluetooth tool/window/dialog once, then send all files?

非常感谢您!

推荐答案

好,这可以通过以下方式完成. 让要发送的文件列表用mMultiSelectData表示.

Well, this can be done by the following means. Let the list of files to be sent be denoted by mMultiSelectData.

ArrayList<Uri> uris = new ArrayList<Uri>();
int length = mMultiSelectData.size();
Intent mail_int = new Intent();
mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
mail_int.setType("*/*");
for(int i = 0; i < length; i++) {
    File file = new File(mMultiSelectData.get(i));
    uris.add(Uri.fromFile(file));
}
mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
mContext.startActivity(mail_int);

这将打开一个选择框.选择Bluetooth,将发送文件列表.

This will open a selection box. Choose Bluetooth and the list of files will be sent.

这篇关于通过蓝牙发送多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆