【问题标题】:Sending Image over Viber通过 Viber 发送图像
【发布时间】:2023-03-05 22:37:01
【问题描述】:

我正在尝试通过 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"));

【问题讨论】:

    标签: android android-intent whatsapp viber


    【解决方案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;
                    }
                }
    

    已修复 .. 希望这对其他人有所帮助。 how to share drawable image via viber and google hangout?这给了我帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-27
      • 2014-01-16
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多