0
我已經通過代碼捕獲屏幕截圖並將其保存在下載目錄中,但保存的文件不可見。無法在下載文件夾中看到保存的文件
當我重新啓動手機,我得到它在下載目錄中可見。
請建議如何解決這個問題。
謝謝。爲節省屏幕
法拍
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// String folderPath = Environment.getExternalStorageDirectory().toString() + "/" + getString(R.string.app_name);
String folderPath = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/";
if (!new File(folderPath).exists()) {
new File(folderPath).mkdir();
}
// image naming and path to include sd card appending name you choose for file
String mPath = folderPath + "/" + getString(R.string.app_name) + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
Toast.makeText(this, "Screen shot saved at " + folderPath, Toast.LENGTH_SHORT).show();
//openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
}
好,會盡量讓你知道。謝謝:) –
它的工作,謝謝。 –