如何在Android中通过蓝牙访问键盘?

问题描述:

我想通过蓝牙访问键盘。如何在Android中通过蓝牙访问键盘?

例如: 如果我在第一个设备中打开键盘并且我想在任何编辑文本中访问另一个设备中的键盘,则两个设备通过蓝牙相互连接。

所以,我怎么能访问该键盘在另一台设备通过蓝牙在android系统?

要检测的EditText键盘弹出:

Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec); 
    final int actualHeight = getHeight(); 

    if (actualHeight > proposedheight){ 
     // Keyboard is shown 
    } else { 
     // Keyboard is hidden 
    } 

    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
} 

要捕捉的关键事件

final EditText edittext = (EditText) findViewById(R.id.edittext); 
edittext.setOnKeyListener(new OnKeyListener() { 
    public boolean onKey(View v, int keyCode, KeyEvent event) { 
     // If the event is a key-down event on the "enter" button 
     if (event.getAction() == KeyEvent.ACTION_DOWN) 

     // keycode should be sent over bluetooth. 

      return true; 
     } 
     return false; 
    } 
}); 

要在活动注入按键只需调用onKeyDown()用适当的KeyEvent


开辟键盘

EditText editText = (EditText) findViewById(R.id.myEdit); 
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
// only will trigger it if no physical keyboard is open 
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 

并关闭它:

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0); 

如果你不感兴趣的其他手机上弹出键盘,简单地忽略这一部分。使用好老:setText()


现在,你是如何形成的通过蓝牙发送这些关键事件是高达you.Hint聊天协议:RemoteDroid used OscMessages

+0

@ Reno ..但我没有使用edittext ...我想访问第一个设备键盘到另一个设备的任何编辑器(Edittext)...所以我怎么能在edittext中获得这些键:例如,如果我想在另一台设备上输入用户名和密码,然后我可以访问第一个设备键盘 –

+0

你,你说什么?你不使用的EditText的但你要使用的EditText?我无法理解你的意思。 – Reno

如果你想要的是有手机的人按一个键与键进入上话机B当前突出显示的字段,那么这是你所需要的:

两部手机上的应用程序(一个在“发送模式”,一个在“接收模式”)。

您需要捕获按键在@Reno的回答编码。然后您需要使用传输机制(在这种情况下为蓝牙)将其传输到其他设备。你应该能够搜索到足够多关于通过蓝牙传输字符串的教程。

你需要在手机B中的应用程序来接收字符串/字符,然后输出到当前选定的领域。这意味着找到关注的领域(再次,在那里回答SO),然后写入该领域(可能是setText("A");)。