我正在尝试通过在 Android 中使用共享 Intent 来共享图像。单击按钮后显示已安装应用程序列表。但是我选择了它不共享的任何一个应用程序。打开应用程序崩溃或某些应用程序告诉发送此内容类型不支持
我的代码:
Intent share = new Intent(Intent.ACTION_SEND);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/");
dir.mkdirs();
Uri uri = Uri.parse(dir+"/img.jpg");
share.putExtra(Intent.EXTRA_STREAM,uri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType("image/jpg");
startActivity(Intent.createChooser(share, "Share Image"));
而且我还授予读取和写入外部存储的权限。
日志猫:
我反复遇到这个错误:
07-06 12:25:11.654: E/SurfaceFlinger(113): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0
最佳答案
试试这个:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(shareIntent, "Share image using"));
关于java - 在 Android 中共享 Intent 不向任何应用程序共享图像(弹出窗口后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31238886/