且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有去得到与出它保存位图的URI到SD卡?

更新时间:2023-09-28 09:15:10

试试这个:

protected void ShareImage(Intent intent) {
    try {
        URL url = new URL(mImageUrl);
        Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        intent.putExtra(Intent.EXTRA_STREAM, getImageUri(mActivity, image));
    } catch (Exception e) {
        e.printStackTrace();
    }
    startActivityForResult(Intent.createChooser(intent, 1001));
}

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    //check for result is OK and then check for your requestCode(1001) and then delete the file

}