在我的应用程序中,我通过ShareActionProvider类添加了一个Share按钮。我试图分享我从文件系统中提取的PNG。问题是,我得到了我抛出以下错误,当我尝试与股票消息应用程序打开失败:EACCES(Permission denied)即使我有权限读取PNG
com.google.android.mms.MmsException: /data/data/com.frostbytedev.wifiqr/files/QRCode.png: open failed: EACCES (Permission denied)
起初我还以为是我的权限共享,但我有我的清单以下权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
,我尝试从文件系统中得到它的位置是在这里:
Uri uri = Uri.fromFile(new File(getFilesDir(), "/QRCode.png"));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM,uri);
provider.setShareIntent(intent);
如果你想知道,他是我保存图像
String fileName = getFilesDir() + "/QRCode.png";
etSSID.setText(fileName);
OutputStream stream = null;
try {
stream = new FileOutputStream(fileName);
bmp.compress(Bitmap.CompressFormat.PNG, 80, stream);
stream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
代码我该如何解决这个问题?
我做了.setReadable和现在得到ENOENT(没有这样的文件或目录) –
@SteveSmith听起来像有什么不对您的路径(或做你做,你保存文件之前?)新增替代件的代码来回答应该工作 – zapl
setReadable()适用于我。 – porquero