获取运行时间在Android上所有应用程序应用程序、时间、Android

由网友(跑调大叔)分享简介:HIII,我工作的一个应用程序中,我必须让运行时间所有被安装在设备上的应用程序。那么,有没有可能知道过了多久别人的应用程序是在手机上运行?例:?多长时间运行在手机上的Gmail应用程序Hiii, I am working on an app in which i have to get the running...

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得到每个服务的启动时间的列表,说明此处。这里有一个片段,检索时间为所有的服务流程。

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));
 }
阅读全文

相关推荐

最新文章