how to share drawable image via viber and google hangout?

左心房为你撑大大i 提交于 2019-12-02 12:06:58

i found a solution to this without using FileProvider or android.resource scheme . thnx CommonsWare for explaining the situation with android.resource scheme

                    int ImageResourse = imageAdapter.mThumbIds[position];

                        Bitmap bitmapToShare = BitmapFactory.decodeResource(
                                getResources(), ImageResourse);

                        File pictureStorage = Environment
                                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                        File noMedia = new File(pictureStorage, ".nomedia");
                        if (!noMedia.exists())
                            noMedia.mkdirs();

                        File file = new File(noMedia, "shared_image.png");
                        if (GeneralFunctions.saveBitmapAsFile(bitmapToShare, file)) {
                            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));


                            ((Activity) getActivity()).setResult(Activity.RESULT_OK, shareIntent); 
                            ((Activity) getActivity()).finish();
                        }
                        else
                        {
                            Toast.makeText(getActivity(), "Sending Error", Toast.LENGTH_LONG).show();
                        }

Few, if any, apps support the android.resource scheme.

You are welcome to share things using the content scheme, such as via FileProvider, as more apps will support that.

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