Skip to content Skip to sidebar Skip to footer

Take Screenshot At Start Main Activit

I went to create android application for crack and break screen and I think that I need to take a screenshot of launcher page in on create and save it and add effect of break in to

Solution 1:

private void captureScreen() {
        View v = getWindow().getDecorView().getRootView();
        v.setDrawingCacheEnabled(true);
        Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache());
        v.setDrawingCacheEnabled(false);
        try {
            FileOutputStream fos = new FileOutputStream(new File(Environment
                    .getExternalStorageDirectory().toString(), "SCREEN"
                    + System.currentTimeMillis() + ".png"));
            bmp.compress(CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Above code do the task of taking screen shot and saving it in png format in sdcard

call this code in onCreate function


Methid 2

On adb shell using below command you can take screen shot.

input keyevent 120

This command does not required any root permission so same you can perform from java code of android application also.

        Process process;
        process = Runtime.getRuntime().exec("input keyevent 120");

More about keyevent code in android see http://developer.android.com/reference/android/view/KeyEvent.html

Here we have used. KEYCODE_SYSRQ its value is 120 and used for System Request / Print Screen key.


Solution 2:

You don't need screen shot Just make the activity background transparent and use ontouchlistener for adding crack effect

Transparent background How do I create a transparent Activity on Android?


Post a Comment for "Take Screenshot At Start Main Activit"