1

I want to take the screen shot of the device. But my coding is take on only my application screen only..I need to take screenshot view screen of the device..and tell how to run on service. time interval should be 500ms for taking screen shot.

Here is screen shot code:

Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Cœur
  • 32,421
  • 21
  • 173
  • 232
Bala
  • 107
  • 2
  • 10
  • possible duplicate of [How to programatically take a screenshot on Android?](http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android) – Rui Marques Nov 11 '13 at 11:17
  • It requires framework changes on device . You can't screenshot of other apps from your application , unless your app takes with framework – Rahul Patil Nov 11 '13 at 11:38
  • check this. http://stackoverflow.com/questions/7762643/android-take-screen-shot-programatically – Ahmad Raza Nov 11 '13 at 13:19
  • possible duplicate of [take device snapshot programmatically in android](http://stackoverflow.com/questions/19493688/take-device-snapshot-programmatically-in-android) – Hamad Dec 23 '13 at 07:20

2 Answers2

0

You Can chek this

View view =  findViewById(R.id.rellayout);
        view.getRootView();
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) 
        {
            File picDir  = new File(Environment.getExternalStorageDirectory()+ "/name");
            if (!picDir.exists())
            {
                picDir.mkdir();
            }
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache(true);
            Bitmap bitmap = view.getDrawingCache();
//          Date date = new Date();
            String fileName = "mylove" + ".jpg";
            File picFile = new File(picDir + "/" + fileName);
            try 
            {
                picFile.createNewFile();
                FileOutputStream picOut = new FileOutputStream(picFile);
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), (int)(bitmap.getHeight()/1.2));//Optional
                boolean saved = bitmap.compress(CompressFormat.JPEG, 100, picOut);
                if (saved) 
                {
                    Toast.makeText(getApplicationContext(), "Image saved to your device Pictures "+ "directory!", Toast.LENGTH_SHORT).show();
                } else 
                {
                    //Error
                }
                picOut.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
            view.destroyDrawingCache();
        } else {


        }
Singhak
  • 7,218
  • 2
  • 27
  • 32
0

if you are able to capture screen shot of your application then simply Create a Receiver and receive the event on what you want to capture screen shot eg.

  <receiver android:name=".VolumeChangeReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
        <intent-filter android:priority="100" >
            <action android:name="android.intent.action.MEDIA_BUTTON" />
            <action android:name="android.media.VOLUME_CHANGED_ACTION" />
        </intent-filter>
    </receiver>

now inside receiver you can right your code i.e.

 Bitmap bitmap;
 View v1 = MyView.getRootView();
 v1.setDrawingCacheEnabled(true);
 bitmap = Bitmap.createBitmap(v1.getDrawingCache());
 v1.setDrawingCacheEnabled(false);

same you can do with power button it is all your wish on what action you want to capture screen shot,

try it might be helpful

Amit
  • 391
  • 3
  • 15