i wrote this code and it works fine,
for testing it creates an overlay view and listen to the touches, so far so good, but how can bring this to the background and still listen to the touch listener.
the idea is, that i want to track all gestures a user does with his phone …
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View startView = inflater.inflate(R.layout.activity_main, null);
setContentView(startView);
changeToInvisible();
startView.setVisibility(View.GONE);
}
private void changeToInvisible(){
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inviView = inflater.inflate(R.layout.invisble,null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(inviView, params);
inviView.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch(View inviView, MotionEvent event) {
Log.d("tag", "touch from invisible app");
return true;
}
});
}
}
invisble.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/trans"
android:orientation="vertical" >
</LinearLayout>
color trans:
<color name="trans">#80000000</color>