【发布时间】:2017-10-18 21:29:41
【问题描述】:
我尝试分享我 SD 卡中的图片。
类 MainActivity.java
Intent shareIntent = new Intent(Intent.ACTION_SEND);
File baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String fileName = "/cats.jpg";
File file = new File(baseDir + fileName);
Uri uri = Uri.fromFile(file);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent.createChooser(shareIntent, "Send Picture"));
我添加到我的 Manifest.xml:
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
图片“猫”在
MySmartphone\Card\DCIM\cats.jpg
当我启动我的应用程序时,我可以选择一个应用程序来分享我的图片。但是当我打开一个时,它无法发送或打开图像。我经常吐司“不支持”或“共享图片错误”。我认为我的 uri 或文件有误,但我找不到我的错误。发短信没问题。
我的 uri:
file:///data/user/0/com.example.jana.showpicture/files/cats.jpg
我的档案: /storage/emulated/0/cats.jpg
【问题讨论】:
-
mage "cats" is in MySmartphone\Card\DCIM\cats.jpg??那是一条不存在的路径。作为程序员的你应该知道得更多。尝试找到图像的真实文件路径。 -
My uri: file:///data/user/0/com.example.jana.showpicture/files/cats.jpg你从哪里得到这个uri?该路径将是内部私有内存。您可以使用 getFilesDir() 访问它。 -
My file: /storage/emulated/0/cats.jpg。该路径与您的 uri 无关,因为它来自 getExternalStorageDirectory()。你的帖子一团糟。