0

我正在尝试通过 viber 或 watzapp 发送图像。Whatsapp 工作正常,但 viber 总是告诉“所选文件似乎不受支持或损坏。请选择其他文件”。知道出了什么问题吗?

这是我的代码

Uri uri = Uri.parse("android.resource://com.example.test/drawable/image_1");
                sharingIntent.setType("image/jpg");
                sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(sharingIntent, "Share image using"));
4

1 回答 1

1
int checkExistence = getResources().getIdentifier("image_"+position, "drawable", getPackageName());
                Bitmap bitmapToShare = BitmapFactory.decodeResource(
                        getResources(), checkExistence);
                File pictureStorage = Environment
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                File noMedia = new File(pictureStorage, ".nomedia");
                if (!noMedia.exists())
                    noMedia.mkdirs();
                File file = new File(noMedia, "meme_shared_image.png");
                if (saveBitmapAsFile(bitmapToShare, file)) {
                    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
                    shareIntent.setType("image/jpeg");
                    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                    startActivity(Intent.createChooser(shareIntent, "Share image using"));
                }
                else
                {
                    Toast.makeText(MainActivity.this, "Sending Error", Toast.LENGTH_LONG).show();
                }

            }

            private boolean saveBitmapAsFile(Bitmap bitmapToShare, File file) {
                FileOutputStream out;
                try {
                    out = new FileOutputStream(file);
                    bitmapToShare.compress(Bitmap.CompressFormat.JPEG, 90, out);
                    return true;
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    return false;
                }
            }

已修复..希望这在某个时候对其他人有所帮助。如何通过 viber 和 google hangout 共享可绘制图像?这给了我帮助

于 2014-09-14T06:13:06.000 回答