0

当我通过 whatsapp 共享图像时,我的代码工作正常......但对于 viber,谷歌视频群聊我得到“找不到照片”错误。这是我的代码:

                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
4

2 回答 2

1

我在不使用 FileProvider 或 android.resource 方案的情况下找到了解决方案。thnx CommonsWare 用于解释 android.resource 方案的情况

                    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();
                        }
于 2014-08-30T08:45:00.950 回答
0

很少有应用程序支持该android.resource方案。

欢迎您使用该content方案共享内容,例如 via FileProvider,因为更多应用程序将支持它。

于 2014-08-15T22:16:08.843 回答