1

I'm using following simple code to tranfer a textfile via bluetooth to an other device:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));
activity.startActivity(Intent.createChooser(sharingIntent,ctx.getResources().getString(R.string.send_pubkey)));

"path" is the full path to the file to be transferred (and is valid). When I try to send the file I get a message the "unknown file" could not be transferred. So...what is wrong here? Why is this file unknown?

Thanks!

Elmi
  • 5,899
  • 15
  • 72
  • 143

2 Answers2

2
String path="/storage/file.mp4";
        if(path.startsWith("file")||path.startsWith("content")||path.startsWith("FILE")||path.startsWith("CONTENT")){

        }else{
            path="file://"+path;
        }
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.setType("video/mp4");
        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.sendTo)));
Sujith S Manjavana
  • 1,417
  • 6
  • 33
  • 60
0

The File Path which you are selecting contains some extra strings like Content:,File: etc. try to remove those unwanted strings from the file. Hope it will solve your problem