有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

除WhatsApp外,java Android共享意图图像共享不起作用

我已经检查了uri,保存的文件是位图及其返回文件。但分享时显示的图像无效。Gmail表示无法附加附件,短信应用无法加载图片

文本共享工作正常

我是Android新手,在通过共享意图共享图像时遇到问题。我在谷歌上搜索了很多,尝试了各种方法,但仍然找不到解决方案

public static void shareWallpaper(Context context, int wallpaperResourceId) {

    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), wallpaperResourceId);
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/wallpaper" + String.valueOf(wallpaperResourceId) + ".jpg";
    OutputStream out = null;
    File file = new File(path);
    try {
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getPath()));
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    context.startActivity(Intent.createChooser(shareIntent, "برنامه مورد نظر خود را انتخاب کنید"));


}

共 (0) 个答案