how to share drawable image via viber and google h

2019-03-03 10:49发布

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

2条回答
祖国的老花朵
2楼-- · 2019-03-03 11:20

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.

查看更多
欢心
3楼-- · 2019-03-03 11:39

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();
                        }
查看更多
登录 后发表回答