Share a file without saving it on the external storage

人走茶凉 提交于 2019-12-24 00:22:46

问题


I am using the following code to allow the user to share a bitmap,

try {

                    File save_dir = Environment.getExternalStorageDirectory();

                    FileOutputStream out = new FileOutputStream(save_dir
                            + "/test.jpg");

                    final_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

                    Intent share = new Intent(Intent.ACTION_SEND);
                    share.setType("image/jpeg");

                    share.putExtra(Intent.EXTRA_STREAM,
                            Uri.parse("file:///" + save_dir + "/test.jpg"));


                    startActivity(Intent.createChooser(share,
                            getString(R.string.share_dialog_title)));

                } catch (Exception e) {
                    Toast.makeText(mainActivity, "Error in sharing.",
                            Toast.LENGTH_LONG).show();
                }

the problem is, the if the device has no SD Card, the file will not be saved.

is there is any good way to save it to the internal storage, in somewhere other apps can access, since saving it in the applications data directory will not allow other applications to access it.

Regards

来源:https://stackoverflow.com/questions/10213296/share-a-file-without-saving-it-on-the-external-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!