Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send multiple files using bluetooth in android programmatically

I am working on an android application that will transfer multiple image files to another mobile device through bluetooth connection.

I have used following transfer method in android:

ArrayList<Uri> uris=new ArrayList<Uri>();
String multifile[]={"/sdcard/aaa.txt","/sdcard/bbb.txt","/sdcard/ccc.txt"};
int len=multifile.length;
Intent Int=new Intent();
Int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
Int.setType("*/*");
for(int i=0;i<len;i++)
{
File file=new File(multifile[i]);
uris.add(Uri.fromFile(file));
}
Int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Int);

This methos successfully transfered the files.But i have only nine images on android phone and then my application will go for another set of 9 images to be transfered,for that i have to call the above chooser wizard to send the files. But i don’t want user to select option from chooser again n again.

Is there any way to send files through that option(bluetooth from wizard) silently(without user intervention) ?

like image 709
user1653853 Avatar asked Nov 03 '22 16:11

user1653853


2 Answers

This worked for me:

Instead of putParcelableArrayListExtra use putExtra(Intent.EXTRA_STREAM, uris)

It was asked a month ago so don't know how relevant it is for you, but may be it helps someone else. :)

like image 97
Suraj Bajaj Avatar answered Nov 15 '22 00:11

Suraj Bajaj


ArrayList<Uri> uris = new ArrayList<Uri>();
        mul = fileSelectorList;
         Log.d("final",""+mul);
        int length = mul.size();

        //Toast.makeText(ImageActivity.this, "Send", Toast.LENGTH_LONG).show();
        //mail_int.setAction(android.content.Intent.ACTION_VIEW);
        mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
    //mail_int.setAction(android.content.Intent.ACTION_TIME_CHANGED);
        mail_int.setType("image/*");
        for(int i = 0; i < length; i++) {
            File file = new File(mul.get(i));
            uris.add(Uri.fromFile(file));

        }

        mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivity(mail_int); 
like image 41
haresh Avatar answered Nov 15 '22 00:11

haresh