点击即可,我的用户可以在社交媒体或whatsapp中共享jpeg。
代码工作正常,但jpeg有点褪色:
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/share.jpg";
OutputStream out = null;
File file = new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path = file.getPath();
Uri bmpUri = Uri.parse("file://"+path);
Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent,"Post with"));
res \ drawable-hdpi文件夹中的jpeg文件。我尝试更改文件夹,但没有效果。 jpeg文件是185 * 200像素