バックグラウンドサービスを使用してスクリーンショットを撮ろうとしています。このサービスはFacebookのチャットヘッドのようなものですが、クリックするとスクリーンショットを撮りたいと思っています。スクリーンショットを撮る - バックグラウンドサービス
私はいくつかのコードを開発してきましたが、それは動作しません。私が試した最後だった:
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/capture/" + now + ".jpg";
// create bitmap screen capture
Bitmap bitmap;
View v1 = chatHead.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ではなく、画面に私のボタンにスクリーンショットを取っています。私はこの問題を知っている
はここにある:
View v1 = chatHead.getRootView();
しかし、私はそれを修正する方法がわかりません。誰でも助けてくれますか?
私は実際にAndroid Studio 2.2.2とAndroid 4.0以上を使用しています。
このようにしてください:https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android Works for me – Developer66
コードはgetwindows();のために動作しません。は非難されました –
すみません、私はそれを知らなかった – Developer66