Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Studio Google Glass emulator中未检测到敲击/滑动_Java_Android_Google Glass_Gesture - Fatal编程技术网

Java Android Studio Google Glass emulator中未检测到敲击/滑动

Java Android Studio Google Glass emulator中未检测到敲击/滑动,java,android,google-glass,gesture,Java,Android,Google Glass,Gesture,我正在运行一个google glass的模拟器,如图所示,通过显示设置、主显示,甚至我的活动(我假装是一张交互式静态卡),它工作得非常完美 我已经看到使用onKeyUp或onKeyDown事件捕获运动手势,但两者都不起作用,我不明白为什么 这是我的密码 public class LiveCardMenuActivity extends Activity { private TextView textView; @Override //isn't catching a thin

我正在运行一个google glass的模拟器,如图所示,通过显示设置、主显示,甚至我的活动(我假装是一张交互式静态卡),它工作得非常完美

我已经看到使用onKeyUp或onKeyDown事件捕获运动手势,但两者都不起作用,我不明白为什么

这是我的密码

public class LiveCardMenuActivity extends Activity {

    private TextView textView;

    @Override //isn't catching a thing, even with onKeyDown (mouse taps or slides in the emulator)
    public boolean onKeyUp(int keycode, KeyEvent event){
        Log.d("tag","keyUp");
        if(keycode == KeyEvent.KEYCODE_DPAD_CENTER){
            Log.d("tag","keypadcenter");
            textView.setText("tap");
        }else if(keycode == KeyEvent.KEYCODE_BACK){
            Log.d("tag","swipedown");
            textView.setText("down");
        }
        return true;
    }

    @Override
    public void onAttachedToWindow() {
            super.onAttachedToWindow();
            setContentView(R.layout.live_card); 
            //does successfully, I can see the layout in the emulator
           //and I can swipe it to the left (returning to the main display successfully)
            textView = (TextView) findViewById(R.id.textView);
            Log.d("tag","attached to window");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.live_card, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_stop:
                // Stop the service which will unpublish the live card.
                stopService(new Intent(this, LiveCardService.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onOptionsMenuClosed(Menu menu) {
        super.onOptionsMenuClosed(menu);
        // Nothing else to do, finish the Activity.
        finish();
    }
}
有人能帮我吗?太好了

尝试在内容视图上调用setFocusabletrue

虽然我不太了解这个模拟器是如何工作的,但这就是如何让它在标准Android上工作的。

当需要使用onKeyDown时,您使用的是onKeyUp。下面是我在Glass项目中使用的一个示例,但我有一个物理Google Glass,没有使用模拟器:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch( keyCode ) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
            Log.e("GESTURE_EVENT", "PostVideoActivity.onKeyDown() TAP/KEYCODE_DPAD_CENTER");
            // DO SOMETHING
            return true;
        case KeyEvent.KEYCODE_BACK:
            Log.e("GESTURE_EVENT", "PostVideoActivity.onKeyDown() SWIPE/KEYCODE_BACK");
            // DO SOMETHING
            return true;
        default:
            Log.wtf("GESTURE_EVENT", "PostVideoActivity.onKeyDown() DEFAULT -- SHOULDNT BE HERE!");
            return false;
    }
}
编辑也许这是模拟器的问题?尽管我对此表示怀疑,但你可以通过为一个已知能工作的手机/手机模拟器创建一些虚拟Android项目来测试这个理论。如果这段代码对其他Android仿真都不起作用,那么它可能是其他的东西