我正在創建啓動服務的android活動。即使用戶正在使用其他應用程序,此服務也用於接收觸摸事件。其onCreate()方法如下。 公共無效的onCreate(){將觸摸事件分派到其他應用程序
super.onCreate();
// create linear layout
touchLayout = new LinearLayout(this);
// set layout width 30 px and height is equal to full screen
LayoutParams lp = new LayoutParams(30, LayoutParams.MATCH_PARENT);
touchLayout.setLayoutParams(lp);
// set color if you want layout visible on screen
//touchLayout.setBackgroundColor(Color.CYAN);
// set on touch listener
touchLayout.setOnTouchListener(this);
// fetch window manager object
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
// set layout parameter of window manager
WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
//30, // width of layout 30 px
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT, // height is equal to full screen
WindowManager.LayoutParams.TYPE_PHONE, // Type Ohone, These are non-application windows providing user interaction with the phone (in particular incoming calls).
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE , // this window won't ever get key input focus
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.LEFT | Gravity.TOP;
Log.i(TAG, "add View");
mWindowManager.addView(touchLayout, mParams);
}
上面,我是創造跨越全高和屏幕寬度的窗口。我已將其設置爲傾聽觸摸事件。但這樣做會阻止其他應用程序收到觸摸事件。所以我正在尋找將我的服務上收到的這些觸摸事件發送到放置我的窗口的後臺應用程序。
請幫忙!