마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

실행중인 어플리케이션들의 사용시간정보

0 추천
안녕하세요.

현재 실행중인 어플리케이션들의 사용시간을 각각 가져오는 방법을 알고 싶습니다.
익명사용자 님이 2016년 1월 5일 질문

1개의 답변

0 추천

Source: http://stackoverflow.com/questions/9736680/how-to-get-info-about-all-running-activities-in-android

ActivityManager m = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE );
List<RunningTaskInfo> runningTaskInfoList =  m.getRunningTasks(10);
Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator();
while(itr.hasNext())
{
    RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next();
    int id = runningTaskInfo.id;
    CharSequence desc = runningTaskInfo.description;
    String topActivity = runningTaskInfo.topActivity.getShortClassName();
    int numOfActivities = runningTaskInfo.numActivities;
}
**Note: ** you have to specify **android.permission.GET_TASKS**
permission in Manifest file 

This method is deprecated with Lolipop, because of its shift towards document centric task management, which could leak personal information. – joecks Jan 25 '15 at 12:12

 

Source: http://stackoverflow.com/questions/22903604/get-all-apps-running-time-on-android

You can get a list of each service's start time by using ActivityManager.RunningServiceInfo.activeSince, described here. Here's a snippet that retrieves the times for all service processes.

ActivityManager activityManager =
    (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services =
    activityManager.getRunningServices(Integer.MAX_VALUE);

long currentMillis = Calendar.getInstance().getTimeInMillis();        
Calendar cal = Calendar.getInstance();

for (ActivityManager.RunningServiceInfo info : services) {
	cal.setTimeInMillis(currentMillis-info.activeSince);

	Log.i(TAG, String.format("Process %s with component %s
            has been running since %s (%d milliseconds)",
            info.process, info.service.getClassName(),
            cal.getTime().toString(), info.activeSince));
}

The Log statement is logging the start time and how any milliseconds the background service processes have been running. You'll want to use the same method calls that the Log statement is using to do something with the data. – scottt Apr 7 '14 at 13:37

i hope this may help you.

익명사용자 님이 2016년 1월 5일 답변
...