First call this method oncreate();
new screenshot().execute();
after create given class:
class screenshot extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... args) {
Log.e("Screenshot", "Called");
mView = view.getRootView();
mView.setDrawingCacheEnabled(true);
b = mView.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString("myapp")
+ ".jpg");
Log.e("My_PatH", "" + myPath);
if (myPath.exists())
myPath.delete();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b,
"Screen", "screen");
Log.e("Bitmap", "" + b);
Log.e("myPath", "" + myPath);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String args) {
}
}