1
我想製作一個MotionEvent來控制一個webiew。如果API低於16一切正常用:帶有API 16和Webview的MotionEvent(Android)
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 500;
float x = 50f;
float y = 50f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent me = MotionEvent.obtain(
downTime,
eventTime,
action,
x,
y,
metaState
);
view.dispatchTouchEvent(me);
不過是API更高,然後我得到一個錯誤有:不是來自SOURCE_CLASS_PIONTER。然後我將代碼更改爲:
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 500;
float x = 50f;
float y = 50f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent.PointerCoords p[] = null;
MotionEvent.PointerProperties p2[] = null;
p[0] = new MotionEvent.PointerCoords();
p[0].x = x;
p[0].y = y;
p2[0] = new MotionEvent.PointerProperties();
p2[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
p2[0].id = 0;
MotionEvent me = MotionEvent.obtain(downTime, eventTime, action, 1, p2, p, metaState, 0, 1f, 1f, 0,0, 0, 0);
view.dispatchTouchEvent(me);
但它沒有工作。你有沒有可以幫助我? 對不起,我的英語不好。
來自德國的問候。