首页 > 移动平台 > 详细

[Android Pro] How to get recent tasks on Android “L”?

时间:2015-10-09 22:41:32      阅读:245      评论:0      收藏:0      [点我收藏+]

reference : http://stackoverflow.com/questions/24590533/how-to-get-recent-tasks-on-android-l/26885469#26885469

<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
String topPackageName ;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    UsageStatsManager mUsageStatsManager = (UsageStatsManager)getSystemService("usagestats");                       
    long time = System.currentTimeMillis(); 
    // We get usage stats for the last 10 seconds
    List<UsageStats> stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000*10, time);                                    
    // Sort the stats by the last time used
    if(stats != null) {
        SortedMap<Long,UsageStats> mySortedMap = new TreeMap<Long,UsageStats>();
        for (UsageStats usageStats : stats) {
            mySortedMap.put(usageStats.getLastTimeUsed(),usageStats);
        }                    
        if(mySortedMap != null && !mySortedMap.isEmpty()) {
            topPackageName =  mySortedMap.get(mySortedMap.lastKey()).getPackageName();                                   
        }                                       
    }
}

 

[Android Pro] How to get recent tasks on Android “L”?

原文:http://www.cnblogs.com/0616--ataozhijia/p/4865267.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!