3

我一直在尝试寻找一些资源,以便为 Android 平台上的可访问性研究项目(APILevel 17)构建 Keylogger Android 应用程序。

应用程序的界面将是一个简单的“EditText”字段,用户使用虚拟屏幕键盘在其中键入[从输入设置中选择所需的键盘后]。

我的目标是为我的应用程序创建一个 Keylog 数据库(使用 SQLite DB,因为我对此很熟悉,但是一个简单的 csv 文件 DB 也可以很好地工作!:)),如下所示:( 在此处输入图像描述插图)

因此,我需要在输入新条目后立即记录每个字符以及时间戳。我一直在尝试使用“ 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 
                            
        }

我的问题是:

  1. 这是实现这个的正确方法吗?
  2. 我可以获取与时间一起键入的恰好一个字符并将其插入到 SQLite DB 中,以便稍后获取和分析吗?
  3. 或者onKeyUp方法会更有用吗?[我还没有使用过尝试过的方法,所以如果有人能指出我使用它来构建键盘记录器,如果这更简单的话,那就太好了!]

*提前感谢任何可以以任何方式帮助我的人!

阿迪*

4

1 回答 1

2

现在你的 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 );

此 Watcher 中包含的每个方法都是通过从键盘输入每个符号来触发的。由于您在输入后获得位置,因此您可以轻松获得输入的字符

要存储您提到的数据,SharedPreferences 将比 DB 更快。(许多写入数据库)如果您的目标至少是 api 11,您可以简单地使用 StringSet Editor.putStringSet如果您的目标较低,它也是可能的,例如:http ://androidcodemonkey.blogspot.com/2011/07/store -and-get-object-in-android-shared.html

.

于 2012-12-23T15:03:40.553 回答