我正在运行一个谷歌眼镜模拟器,如下所示,通过显示设置、主显示屏甚至我的 Activity (我假装是交互式静态卡),工作得非常完美。
http://mobilevangelist.com/2014/01/02/gdk-and-the-android-emulator/
我发现运动手势是使用 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();
}
}
有人可以帮我解决这个问题吗?泰姆!
最佳答案
尝试在内容 View 上调用 setFocusable(true)
。
虽然我不太了解这个模拟器的工作原理,但这就是您如何让它在标准 Android 上工作的方法。
关于java - Android Studio Google Glass 模拟器中未检测到点击/滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293966/