0
我想创建一个记录用户活动时,Android手机/平板电脑获得创建登录PC连接
我搜索了很多的,我无法找到如何捕捉USB接口连接到PC的日期和时间事件
我已经实施了log4j
记录异常和手机用户的步骤。但我无法登录任何关于PC连接。
请帮帮我。 感谢
我想创建一个记录用户活动时,Android手机/平板电脑获得创建登录PC连接
我搜索了很多的,我无法找到如何捕捉USB接口连接到PC的日期和时间事件
我已经实施了log4j
记录异常和手机用户的步骤。但我无法登录任何关于PC连接。
请帮帮我。 感谢
您可以使用下面的接收器,android.intent.action.UMS_CONNECTED
<receiver android:name="org.usbcheck.USBReceiver" >
<intent-filter>
<action android:name="android.intent.action.UMS_CONNECTED" />
<action android:name="android.intent.action.UMS_DISCONNECTED" />
</intent-filter>
</receiver>
用于记录
public class USBReceiver extends BroadcastReceiver {
public Context _context;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(
"android.intent.action.UMS_CONNECTED")) {
Log.d("Connected", "Log Message");
}
else if (intent.getAction().equalsIgnoreCase(
"android.intent.action.UMS_DISCONNECTED")) {
Log.d("DisConnected", "Log Message");
}
}
}
的主要问题,同时检查android.intent.action.ums_connected是 表示使用MTP协议的设备(如Samsung Nexus Galaxy) 未收到此广播。
或者检查的情况下,设备充电带有USB充电模式
// How are we charging?
int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BATTERY_PLUGGED_AC;
来源:http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
感谢阳光的回答 但我怎样才能创建日志使用上述接收器? – Hemantwagh07
编辑答案:在您的接收器中,您可以添加日志 –
但是,此代码需要位于应用程序 之一中,并且如果该应用程序未打开,则不会记录任何内容。 我对吗? – Hemantwagh07