如何在android中意图共享图像位图?

时间:2019-06-15 06:06:06

标签: java android android-intent

(此问题不能重复!)

我如何通过意图共享图像?

我尝试过

Android Share Intent for a Bitmap - is it possible not to save it prior sharing?

How to share image to social media with bitmap?

share image with URL android share intent

但是只能在模拟器上工作,而不能在实际的手机上工作,并且出现以下代码错误:

//b method : convert inputstream to bitmap
String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), b(inputStream) ,"title", null);

完整代码:

InputStream is = getAssets().open(imageName.getText().toString());
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String path = Environment.getExternalStorageDirectory()+"/" + APP_NAME()+"/pictures/"+ls+"/" ;
new File(path).mkdirs();
String fileName = System.currentTimeMillis() + imageName.getText().toString().replace("pic/" , "");
FileOutputStream fileOutputStream = new FileOutputStream(new File(path+fileName));
fileOutputStream.write(buffer);
fileOutputStream.close();
InputStream inputStream = new FileInputStream(new File(path+fileName));

String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), b(inputStream) ,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM , bitmapUri);
startActivity(intent);


//Intent intent = new Intent(android.content.Intent.ACTION_SEND);
//intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
//intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//intent.setType("image/*");
//startActivity(intent);

1 个答案:

答案 0 :(得分:0)

通过对我的代码进行少量更改就解决了我的问题:

jQuery(document).ready(function($){
    $('.et_pb_portfolio_item:nth-child(odd)').each(function(){
        $(this).find(".et_pb_module_header").insertBefore(".et_portfolio_image");
    });
});

完整代码:

Uri bitmapUri = Uri.parse (new File (path + fileName) .toString ());