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);
}
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?
Thank you very much in advance!
It's quite a simple exercise but this comes with a cost! SDCard storage space.
Yes, you do need to dump the multiple files onto the SDCard for the purpose.
For each file dumped into the SDCard you need to build up an array list of
Uri
.The crucial part is to explicitly tell the intent that the chooser must be able to read the dumped files on the SDCard by way of granting the read permission, and more importantly, add the array list to the intent's extra parcelable bundle.
Then all files selected will be sent via the Android's bluetooth run-time facility. By the way, you may have to explicitly specify the
setType
for the files, for example,image/jpeg
as in:The only onus is on your part to clean up the remnants of the SDCard file-system which is something, for the most part, android users absolutely loathe!