how to share drawable image via viber and google hangout?

為{幸葍}努か 提交于 2019-12-31 07:07:31

问题


my code works fine when i share a image via whatsapp....but for viber , google hangout im getting "can't find photo" error. this is my code :

                int ImageResourse=imageAdapter.mThumbIds[position];

            Uri path = Uri.parse("android.resource://dragonflymobile.stickers.lifestickers/" + ImageResourse);

                Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, path); 

                ((Activity)getActivity()).setResult(Activity.RESULT_OK, shareIntent); //set the file/intent as result
                ((Activity)getActivity()).finish(); //close your application and get back to the requesting application like GMail and WhatsApp

回答1:


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();
                        }



回答2:


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.



来源:https://stackoverflow.com/questions/25334647/how-to-share-drawable-image-via-viber-and-google-hangout

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