我正在尝试创建一个密钥记录器类型的应用程序,供家长在互联网打开时在他们的孩子手机上使用。主要是聊天和上网。我知道有应用程序,但我需要自学和构建一个。我尽可能地用我的小知识准备了一个代码。但我不确定我是否可以通过在后台运行来捕获所有键盘输入事件。
接收者类
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
ConnectivityManager connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isConnected = wifi != null && wifi.isConnectedOrConnecting()
|| mobile != null && mobile.isConnectedOrConnecting();
if (isConnected) {
Log.d("Network Available ", "Yes");
Intent i = new Intent(context, services.class);
context.startService(i);
} else {
Log.d("Network Available ", "NO");
}
}
服务类
public class services extends Service{
@Override
public void onCreate() {
Log.i("worked", "A");
}
public IBinder onBind(Intent intent) {
return null;
}
boolean doKeyDown(int keyCode, KeyEvent msg) {
switch (keyCode) {
case KeyEvent.KEYCODE_A:
Log.i("Pressed : ", "A");
break;
case KeyEvent.KEYCODE_B:
Log.i("Pressed : ", "B");
break;
case KeyEvent.KEYCODE_C:
Log.i("Pressed : ", "C");
break;
case KeyEvent.KEYCODE_D:
Log.i("Pressed : ", "D");
break;
case KeyEvent.KEYCODE_E:
Log.i("Pressed : ", "E");
break;
case KeyEvent.KEYCODE_F:
Log.i("Pressed : ", "F");
break;
case KeyEvent.KEYCODE_G:
Log.i("Pressed : ", "G");
break;
case KeyEvent.KEYCODE_H:
Log.i("Pressed : ", "H");
break;
}
return false;
}
}