0

I want to check if android phone and processor is idle or not. Screen on/off is not sufficient for this case because may be music is playing even if the light is off and there are many examples like that. Can anybody give me any proper way to check this thing??

Ateeq
  • 520
  • 1
  • 5
  • 17

1 Answers1

0

the CPU is never completely idle, since there are system processes being run in background and your own app is running as well. About the rest of the question:

    ActivityManager am = (ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE);
    List apps = am.getRunningTasks(99);

getRunningTasks() will return a List of currently active tasks, though I would not consider this method as a very reliable (please read the method's javadoc for more info). The int you pass to the method is the desired max number of tasks.

Droidman
  • 11,485
  • 17
  • 93
  • 141
  • I can also get the number of processes but that does not fulfill my requirement I want to check if user is not using his phone – Ateeq Oct 04 '13 at 17:44
  • Not completely idle I know services are running in background as well as the system processes. I want to know if the phone is not used by its user. – Ateeq Oct 04 '13 at 17:47
  • 1
    @Ateeq please refer to this question: http://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service/5528441#5528441 if there's no foreground Activity means the user is not interacting with the device – Droidman Oct 04 '13 at 18:07
  • but the example I mentioned in my question what if the user is listening songs the music player is not in foreground but still the user is using his phone. – Ateeq Oct 04 '13 at 18:18
  • well you could call getRunningServices() on the ActivityManager to get the services, however you'll somehow filter out the system ones – Droidman Oct 04 '13 at 22:20