1

i have this screenshot app which work's fine in its own activity.But i wanted it to capture any screen or any other application's activity or even inside a game. So for that i instantiated it to a service, but it fails. Here's the code:

public class CaptureService extends Service {


private ImageView c_icon;
private View m_icon;
private WindowManager wm, wmm;
private GestureDetectorCompat clik_detector;
private RelativeLayout rel;  

public void onCreate()
{
    super.onCreate();
    icon_pop();

    clik_detector = new GestureDetectorCompat(this, new IconGestureListener());

}  

Created a windowmanager so that it can hold the capture logo:

private void icon_pop()
{
    wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    c_icon = new ImageView(this);
    c_icon.setImageResource(R.drawable.c_icon);
    c_icon.setClickable(true);
    c_icon.setEnabled(true);


    final WindowManager.LayoutParams iconparam = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSPARENT);

    iconparam.gravity = Gravity.TOP | Gravity.LEFT;
    iconparam.x = 0;
    iconparam.y = 0;

    wm.addView(c_icon, iconparam);


    c_icon.setOnTouchListener(new View.OnTouchListener() {
        private WindowManager.LayoutParams icon_param = iconparam;
        private int initialX;
        private int initialY;
        private float initialTouchX;
        private float initialTouchY;

        @Override
        public boolean onTouch(View v, MotionEvent e) {
            clik_detector.onTouchEvent(e);
            switch (e.getAction()) 
            {
            case MotionEvent.ACTION_DOWN:
                initialX = icon_param.x;
                initialY = icon_param.y;
                initialTouchX = e.getRawX();
                initialTouchY = e.getRawY();
                break;
            case MotionEvent.ACTION_UP:

                break;
            case MotionEvent.ACTION_MOVE:
                icon_param.x = initialX + (int) (e.getRawX() - initialTouchX);
                icon_param.y = initialY + (int) (e.getRawY() - initialTouchY);
                wm.updateViewLayout(c_icon, icon_param);                    
                break;
            }
            return false;
        }
    });
}  

But when i instatiated touch event it only captures the space inside windowmanager i.e. only the logo.

public boolean onTouchEvent(MotionEvent event)
{
    this.clik_detector.onTouchEvent(event);
    return true;
}

class IconGestureListener extends GestureDetector.SimpleOnGestureListener
{

    @Override
    public boolean onDown(MotionEvent e) {

        return super.onDown(e);
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        // TODO Auto-generated method stub
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    Bitmap bitmap = rootView.getDrawingCache();
    saveBitmap(bitmap);
    Toast.makeText(getApplicationContext(), "Successfully saved", Toast.LENGTH_SHORT).show();
        return super.onSingleTapConfirmed(e);
    }

}  

How do i make it take screenshots of every screen or every activity of any app or game.
thanks in advance

amitlalan
  • 11
  • 2
  • HI Kindly refer the following link: [This was already discussed here.][1] [1]: http://stackoverflow.com/questions/15276346/how-to-take-screenshot-programmatically-and-save-it-on-gallery – Sivakumar Jul 24 '14 at 11:17
  • 3
    You can't. Only root apps can do this. Otherwise, Fred Malwarerus installs a service on your phone to provide GoodFeatures(TM) which actually takes screen shots of your contact and online banking apps and sends them to TimbuktoosVille in Russia. – Simon Jul 24 '14 at 11:18
  • @Sivakumar i tried the above link and when i start service the application shuts down. I am trying to invoke screenshot through a button that's actually a service object.what do i do now? – amitlalan Jul 24 '14 at 11:57

0 Answers0