【发布时间】:2014-05-21 08:18:09
【问题描述】:
我创建了一个截取屏幕截图的函数,将其保存在 .jpeg 类型的临时文件中,然后允许用户在 Facebook 或蓝牙上共享它。这是我的分享功能:
public Bitmap Share(View v) {
// Sound
soundPool.play(button_sound, 1.0f, 1.0f, 0, 0, 1.0f);
// Image
v.setDrawingCacheEnabled(true);
v.setLayerType(View.LAYER_TYPE_NONE, null);
Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
// Share
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
String filel = "file://" + Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg";
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(filel));
startActivity(Intent.createChooser(share, "Share Image"));
return bitmap;
}
我的问题是它会截取屏幕截图,但是当我尝试分享新的截图时,它总是一遍又一遍地分享相同的截图。当我使用文件管理器检查时,图像不同。所以我不知道是什么原因造成的。
非常感谢您抽出宝贵时间。
【问题讨论】:
-
你有没有注意到新创建的文件名和旧文件名一样,为什么不随机生成一个文件名。
标签: android image file screenshot sharing