Posts

Showing posts from October, 2014

How to programmatically take a screenshot on Android?

First of All you need to add  WRITE_EXTERNAL_STORAGE permission in your Android manifest since will be writing to the external storage. To write to the external storage, we must request the  WRITE_EXTERNAL_STORAGE  permission in your  manifest file .     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > Bitmap bitmap; //Create a bitmap object /*  android.graphics.Bitmap -  http://developer.android.com/reference/android/graphics/Bitmap.html */   View scrView = findViewById(R.id.root);    // Select the view   scrView.setDrawingCacheEnabled(true);    bitmap = Bitmap.createBitmap( scrView .getDrawingCache());  // returns an immutable bitmap from source bitmap    scrView .setDrawingCacheEnabled(false);   ByteArrayOutputStream bytes = new ByteArrayOutputStream(); //  http://developer.android.com/reference/java/io/ByteArrayOutputStream.html   bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); //Write a compressed ver