【问题标题】:Unable to open file for sharing from Bluetooth from external storage无法从外部存储打开文件以从蓝牙共享
【发布时间】:2015-07-29 12:29:27
【问题描述】:

我正在尝试使用 Intent 来使用蓝牙共享文件,但我不知道为什么它显示我吐司“无法打开文件进行共享”我也在不同的文件上尝试过它,但它做的一样,我正在分享我在清单中使用的代码和权限...

    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"));

到目前为止我添加的权限

<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" />

【问题讨论】:

  • 也发布你的 logcat
  • 感谢@Exception,我在 logcat 中寻找一些相关的东西,但我没有找到任何与蓝牙相关的东西,即使它没有显示与我正在执行的操作相关的任何东西

标签: java android android-intent bluetooth


【解决方案1】:

试试这个

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);

或者 仔细阅读本文并实施此How to send file using bluetooth on android programatically?

或阅读本教程以通过蓝牙分享 http://kpbird.blogspot.in/2011/04/android-send-image-via-bluetooth.html

并且不要忘记在清单中声明权限

【讨论】:

    【解决方案2】:

    如果图片在图片文件夹中,那么路径将是这样的

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多