Android 保存图像文件并返回whatsapp

Android 保存图像文件并返回whatsapp,android,image,drawing,Android,Image,Drawing,我使用以下代码将图像文件保存到外部存储器 drawView.setDrawingCacheEnabled(true); String img = MediaStore.Images.Media.insertImage(getContentResolver(),drawView.getDrawingCache(),UUID.randomUUID().toString()+".jpeg", "doodle"); 我想使用intent将此保存的文件返回到Whatsapp。有人能帮我查一下密码吗?我是

我使用以下代码将图像文件保存到外部存储器

drawView.setDrawingCacheEnabled(true);
String img = MediaStore.Images.Media.insertImage(getContentResolver(),drawView.getDrawingCache(),UUID.randomUUID().toString()+".jpeg", "doodle");
我想使用intent将此保存的文件返回到Whatsapp。有人能帮我查一下密码吗?我是android新手,非常感谢!谢谢:)

试试这段代码

Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
    f.createNewFile();
    FileOutputStream fo = new FileOutputStream(f);
    fo.write(bytes.toByteArray());
} catch (IOException e) {                       
        e.printStackTrace();
}

share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));

它说mBitmap尚未初始化。我将其初始化为null,但应用程序停止工作。您可以发布错误日志吗。同时更改SD卡图像在给定代码中的位置