すべての Android デバイスでスクリーン ショットを撮影できるわけではないことは承知していますが、ユーザーのゲーム画面のスクリーン ショットをプログラムで撮影して、友人などと共有できるようにしたいと考えています。
誰もこれを行う方法を知っていますか? ここに投稿されているいくつかのソリューションを試しました:
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;
// create bitmap screen capture
Bitmap bitmap;
View v1 = activity.getCurrentFocus().getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, 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 = activity.getCurrentFocus().getRootView(); で null ポインターを取得しています。