2

I have been trying to detect when the user launches an application on his/her device.

So I found this solution:

https://stackoverflow.com/a/7239840/833219

I added this code inside of a thread. So my application get the log every 3 milliseconds, but I cannot find the difference between logs, so I cannot detect what code is meant for the user's app launching.

Here is an example of the log I got when I add this line:

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={}

Using this code, how can I detect that the user launched an application?

Community
  • 1
  • 1
haythem souissi
  • 3,263
  • 7
  • 50
  • 77
  • You may want to look at the second answer to this question: http://stackoverflow.com/questions/3290936/android-detect-when-other-apps-are-launched – James Black Jun 03 '12 at 23:59

2 Answers2

2

Reading the logs is a horrible idea, and also broken across versions of the system. There is actually a broadcast intent for which you can register here: ACTION_PACKAGE_FIRST_LAUNCH, however, take note that this is only available in API level 12+.

Kristopher Micinski
  • 7,572
  • 3
  • 29
  • 34
1

you can detect application launch with tag of ActivityManager in logs.

in log you can find useful data.you can detect run packages.

for example :

06-06 16:09:06.007: I/ActivityManager(1663): Starting: Intent { act=android.intent.action.MAIN flg=0x10840000 cmp=com.android.phone/.InCallScreen } from pid -1

it is com.android.phone package and InCallScreen starts for first page.

you can check packages name and detect when your target application launched.

M.Movaffagh
  • 1,284
  • 5
  • 20
  • 33
  • i always got this line and i can't see what changes in the log when i lunch a new application? – haythem souissi Jun 07 '12 at 16:43
  • This doesn't always work, as different devices may log this differently. For example, in ICS, "Starting" is now "START", and the rest of the line is different as well. Also, in the Samsung Galaxy S2 with ICS, nothing is output to the log when an app launches. – user1118764 Aug 03 '12 at 08:50