czy jest tam, aby uzyskać uri bitmapy z out zapisać go do sdcard?

Robię aplikację, która pozwala użytkownikowi udostępnić obraz za pomocą Android intent, ale jak uzyskać ten uri z

Bitmapy z out trzeba zapisać go do sdcard i

Użyłem tego kodu, który działa dobrze, ale nie muszę zapisywać tej bitmapy na sdcard

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

Muszę dostać ten uri z out Zapisz tę bitmapę do sdcard

Author: Ahmed Mousa, 2014-09-26

2 answers

Spróbuj tego:

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

}
 17
Author: Sagar Pilkhwal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-26 12:49:22

Try this way

protected void tryToShareImage(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();
    }
    startActivity(Intent.createChooser(intent, "Share using..."));
}

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);
}

Następnie możesz usunąć Pliki za pomocą File.delete()

 1
Author: Maveňツ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-26 12:39:34