我一直在尝试检测用户何时在他/她的设备上启动应用程序。
所以我找到了这个解决方案:
https://stackoverflow.com/a/7239840/833219
我在线程中添加了这段代码。所以我的应用程序每 3 毫秒获取一次日志,但我找不到日志之间的区别,所以我无法检测到用户应用程序启动的代码是什么。
这是我添加此行时得到的日志示例:
String w = log.toString();
Log.i("LockService","w ="+w);
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc android.process.media for broadcast com.android.providers.media/.UsbReceiver: pid=375 uid=10013 gids={1015, 1023, 1024, 2001, 3003, 3007}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.inputmethod.latin.dictionarypack for content provider com.google.android.inputmethod.latin.dictionarypack/.DictionaryProvider: pid=407 uid=10043 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc android.process.acore for content provider com.android.providers.userdictionary/.UserDictionaryProvider: pid=421 uid=10002 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): W/ActivityManager( 142): Unable to start service Intent { act=com.android.internal.telephony.IWapPushManager }: not found
06-04 00:20:14.765: I/LockService(854): W/ActivityManager( 142): Unable to start service Intent { act=com.android.ussd.IExtendedNetworkService }: not found
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.android.settings for broadcast com.android.settings/.widget.SettingsAppWidgetProvider: pid=476 uid=1000 gids={1015, 3002, 3001, 3003, 3007}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.android.contacts for broadcast com.android.contacts/.calllog.CallLogReceiver: pid=505 uid=10002 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.android.providers.calendar for broadcast com.android.providers.calendar/.CalendarReceiver: pid=545 uid=10007 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Config changed: {1.0 605mcc1mnc fr_FR layoutdir=0 sw320dp w320dp h508dp nrml long port finger -keyb/v/h -nav/h s.4}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.deskclock for broadcast com.google.android.deskclock/com.android.deskclock.AlarmInitReceiver: pid=562 uid=10012 gids={}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.email for broadcast com.google.android.email/com.android.email.service.EmailBroadcastReceiver: pid=577 uid=10014 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.exchange for service com.google.android.exchange/com.android.exchange.ExchangeService: pid=596 uid=10025 gids={3003, 1015}
06-04 00:20:14.765: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.apps.genie.geniewidget for broadcast com.google.android.apps.genie.geniewidge
06-04 00:20:15.082: I/LockService(854): w =--------- beginning of /dev/log/system
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Memory class: 48
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Config changed: {1.0 0mcc0mnc fr_FR layoutdir=0 sw320dp w320dp h508dp nrml long port ?uimode ?night finger -keyb/v/h -nav/h s.2}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): System now ready
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.android.systemui for service com.android.systemui/.SystemUIService: pid=210 uid=1000 gids={1015, 3002, 3001, 3003, 3007}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.gsf.login for service com.google.android.gsf.login/com.google.android.gsf.loginservice.GoogleLoginService: pid=238 uid=10018 gids={3003, 1015, 1007, 2001, 3006}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.google.process.gapps for content provider com.google.android.gsf/.gservices.GservicesProvider: pid=262 uid=10018 gids={3003, 1015, 1007, 2001, 3006}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Config changed: {1.0 0mcc0mnc fr_FR layoutdir=0 sw320dp w320dp h508dp nrml long port finger -keyb/v/h -nav/h s.3}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.android.wallpaper for service com.android.wallpaper/.nexus.NexusWallpaper: pid=289 uid=10027 gids={1006}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.google.android.inputmethod.latin for service com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME: pid=301 uid=10024 gids={}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.android.phone for added application com.android.phone: pid=316 uid=1001 gids={3002, 3001, 3003, 1015}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.android.nfc for added application com.android.nfc: pid=331 uid=1027 gids={3002, 3001}
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 0
06-04 00:20:15.082: I/LockService(854): I/ActivityManager( 142): Start proc com.android.launcher for activity com.android.launcher/com.android.launcher2.Launcher: pid=354 uid=10026 gids={}
使用此代码,我如何检测到用户启动了应用程序?