简体   繁体   中英

Unable to open file for sharing from Bluetooth from external storage

I am trying to use intent for sharing a file using bluetooth but i don't know why is it showing me toast "Unable to open file for sharing" i have tried it on different files as well but it do the same, i am sharing my code and permissions i have used in manifest ...

    String sharePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Aaa.jpg";
    Uri uri = Uri.parse(sharePath);
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share Sound File"));

permissions i have addedso far

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

try This

File sourceFile = new File("//mnt/sdcard/TviderFB.apk"); 
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
Intent.setType("image/jpeg"); 
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(sourceFile));
startActivity(intent);

Or Read this carefully and implement this How to send file using bluetooth on android programatically?

Or Read This Tutorial to share via bluetooth http://kpbird.blogspot.in/2011/04/android-send-image-via-bluetooth.html

And Do not Forget to Declare Permissions in the manifest

If image is in picture folder then path will be like this

String sharePath = Environment.getExternalStoragePublicDirectory
        (Environment.DIRECTORY_PICTURES) + "/Aaa.jpg"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM