我創建了一個截屏截圖的功能,將其保存在類型爲.jpeg的臨時文件中,然後允許用戶在Facebook或藍牙上共享它。這裏是我的共享功能:在Android上分享屏幕截圖。每次共享相同的圖像
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;
}
我的問題是,它需要的截圖,但隨後過來,當我嘗試一種全新的分享一個超過總是共享相同的屏幕截圖。當我使用文件管理器檢查時,圖像是不同的。所以我不知道是什麼原因造成的。
非常感謝你的時間。
你有沒有注意到新創建的文件的名稱與舊的名稱相同,爲什麼不生成隨機文件名? –