获取运行时间在Android上所有应用程序 [英] Get all apps running time on android

查看:547
本文介绍了获取运行时间在Android上所有应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HIII, 我工作的一个应用程序中,我必须让运行时间所有被安装在设备上的应用程序。 那么,有没有可能知道过了多久别人的应用程序是在手机上运行?例:?多长时间运行在手机上的Gmail应用程序

Hiii, I am working on an app in which i have to get the running time of all the apps that are installed on the device. So, is it possible to know how long somebody else's app is running for on the phone? Ex: How long is the gmail app running on the phone?

有没有 API 这还是我们要开发有自己的逻辑,使其工作???

Is there any API for this or we have to develop are own logic to make it work???

推荐答案

您可以通过使用ActivityManager.RunningServiceInfo.activeSince得到每个服务的启动时间的列表,说明<一href="http://developer.android.com/reference/android/app/ActivityManager.RunningServiceInfo.html#activeSince"相对=nofollow>此处。这里有一个片段,检索时间为所有的服务流程。

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));
 }

这篇关于获取运行时间在Android上所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆