我一直在寻找一些资源,以便为安卓平台(APILevel 17)上的可访问性研究项目构建一个键盘记录器Android应用程序。
应用程序的接口将是一个简单的"EditText"字段,用户在从输入设置中选择所需的键盘后使用虚拟屏幕键盘进行键入。
我的目标是为我的应用程序创建一个密钥日志数据库(使用SQLite DB,因为我对此很熟悉,但是一个简单的csv也会工作得很好!:),如下所示:
(图示)
因此,我需要在输入一个新条目时立即将每个字符与时间戳一起记录下来。我一直在尝试用"TextWatcher“类来验证
EditText KeyLogEditText = (EditText) findViewById(R.id.editTextforKeyLog);
TextWatcher KeyLogTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{ }
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3)
{ }
@Override
public void afterTextChanged(Editable arg0) {
// TODO Log the characters in the SQLite DB with a timeStamp etc.
// Here I call my database each time and insert an entry in the database table.
//I am yet to figure out how to find the latest-typed-character by user in the EditText
}
我的问题是:
*预先感谢任何能帮助我的人!
艾迪特*
发布于 2012-12-23 15:03:40
目前,您的TextWatcher还没有绑定到EditText
您应该在您的addTextChangedListener(TextWatcher yourWatcher)
上使用EditText。以下是我的例子:
smsET.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d(TAG, "onTextChanged start :"+start +" end :"+count);}
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
Log.d(TAG, "beforeTextChanged start :"+start +" after :"+after);
}
public void afterTextChanged(Editable s) {
int lastPosition = s.length()-1;
char lastChar = s.charAt(lastPosition);
Log.d(TAG, "afterTextChange last char"+lastChar );
}
});
在您的代码中,应该是这样的:
KeyLogEditText.addTextChangeListener(KeyLogTextWatcher );
包含在此守望者中的每一种方法都是通过从键盘输入每个符号来触发的。由于您在输入后得到位置,所以您可以轻松地获得输入的字符。
要存储您提到的数据,SharedPreferences将比DB更快。(许多写到DB)如果您的目标至少是api 11,您可以简单地使用StringSet Editor.putStringSet,如果您的目标较低,也是可能的,例如:http://androidcodemonkey.blogspot.com/2011/07/store-and-get-object-in-android-shared.html
。
https://stackoverflow.com/questions/14011633
复制相似问题