I've written an app, touch button, and then open an other app(like facebook), then I want to do touchevent by coordinate, but it not work. It seems like a hack, but actually do screen touch, Does anyone know why the dispatchTouchEvent not work? Is it because of the security? so how to let it work....Thanks.
private void jumpApp(String appName) {
System.out.println("entry");
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Jumping app...", Toast.LENGTH_LONG).show();
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(appName);
startActivity(intent);
Log.d(TAG, "sleep 3000ms");
sleep(5000);
Log.d(TAG, "after 3000ms");
Toast.makeText(MainActivity.this, "continue...", Toast.LENGTH_LONG).show();
touchEvent(385, 466);
}
private void touchEvent(int x, int y) {
long firstTime = SystemClock.uptimeMillis();
final MotionEvent firstEvent = MotionEvent.obtain(firstTime, firstTime,
MotionEvent.ACTION_DOWN, x, y, 0);
long secondTime = firstTime + 30;
final MotionEvent secondEvent = MotionEvent.obtain(secondTime,
secondTime, MotionEvent.ACTION_UP, x, y, 0);
dispatchTouchEvent(firstEvent);
dispatchTouchEvent(secondEvent);
}