Android屏幕截图应用无法捕获其自身活动之外的任何屏幕

时间:2014-07-24 11:11:37

标签: android screenshot

我有这个截图应用程序,它在自己的活动中运行良好。但我希望它能捕获任何屏幕或任何其他应用程序的活动,甚至在游戏中。因此,我将它实例化为服务,但它失败了。这是代码:

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());

}  

创建了一个窗口管理器,以便它可以保存捕获徽标:

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;
        }
    });
}  

但是当我实现触摸事件时,它只捕获窗口管理器内的空间,即仅捕获徽标。

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);
    }

}  

如何拍摄每个屏幕或任何应用或游戏的每项活动的屏幕截图 提前谢谢

0 个答案:

没有答案