chr*_*667 9 java android share bitmap android-intent
也许这是一个简单的问题:我想通过网络分享一个位图,用默认共享"意图"分享到twitter/facebook/etc.
我找到的代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
sendIntent.putExtra(Intent.EXTRA_TEXT,
"See my captured picture - wow :)");
startActivity(Intent.createChooser(sendIntent, "share"));
Run Code Online (Sandbox Code Playgroud)
需要在位图"IDONTKNOW"处填充位图.(this.bitmap)
如果不将位图保存到内部sd,我发现无法处理此问题.
问候
简单地说,您可以将位图从外部存储转换为PNG.
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = new File(path, getCurrentTime()+ ".png");
FileOutputStream fileOutPutStream = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream);
fileOutPutStream.flush();
fileOutPutStream.close();
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过Uri.parse获取URI:
return Uri.parse("file://" + imageFile.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)