画面のスクリーンショットを撮り、SDカードに書き込むための解決策は次のとおりです
ルートレイアウトの設定:
View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);
レンダリングされたビューを取得する関数:
private void getScreen()
{
View content = findViewById(R.id.layoutroot);
Bitmap bitmap = content.getDrawingCache();
File file = new File( Environment.getExternalStorageDirectory() + "/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
追加することを忘れないでください
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
AndroidManifestに。