获取以下路径但无法访问屏幕截图,任何想法?
Brings up path : /storage/emulated/0/test-screenshots/screenshot-001.png
使用方法时:
尝试使用Android Espresso中的以下方法捕获屏幕截图:
takeScreenshot("screenshot-001", getActivity());
public static void takeScreenshot(String name, Activity activity)
{
// In Testdroid Cloud, taken screenshots are always stored
// under /test-screenshots/ folder and this ensures those screenshots
// be shown under Test Results
String path = Environment.getExternalStorageDirectory()+ "/test-screenshots/" + name + ".png";
Log.d("Logs", "Image Path is " + path);
View scrView = activity.getWindow().getDecorView().getRootView();
scrView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(scrView.getDrawingCache());
scrView.setDrawingCacheEnabled(false);
OutputStream out = null;
File imageFile = new File(path);
try {
out = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
} catch (java.io.FileNotFoundException e) {
// exception
} catch (java.io.IOException e) {
// exception
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception exc) {
}
}
}