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

本文介绍如何在Android L中获取最近使用的应用任务,包括使用`PackageManager`权限、`UsageStatsManager`来获取应用使用统计数据,以及通过代码实现获取最近10秒内使用的应用包名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

转载于:https://www.cnblogs.com/0616--ataozhijia/p/4865267.html

### Intellij IDEA Plugin AllGet Features and Usage #### Overview of AllGet Plugin AllGet is a powerful plugin designed specifically for IntelliJ-based IDEs that aims at enhancing developer productivity by providing comprehensive support across various aspects of development tasks. This includes but not limited to file management, project navigation, and utility functions. #### Key Features Provided by AllGet ##### Enhanced File Management Capabilities The AllGet plugin offers advanced functionalities related to handling files within projects such as opening recent or favorite files quickly through shortcuts[^1]. Users benefit from faster access times which contribute towards improved efficiency during coding sessions. ##### Improved Navigation Tools With built-in tools like fuzzy search capabilities over class names, method signatures etc., navigating large codebases becomes significantly easier with this toolset provided by the AllGet extension[^5]. ##### Utility Functions Integration Additional utilities integrated into daily workflows are made available via AllGet including clipboard history manager allowing easy retrieval of past copied items without leaving the editor environment entirely[^4]. #### Installation Process For installing any third-party plugins including 'AllGet', users need to open their instance of IntelliJ IDEA then navigate through `File` -> `Settings`. Within settings dialog box select `Plugins`, switch to `Marketplace` tab where searching for "AllGet" will lead directly to its installation page after clicking on install button followed by restarting application once completed successfully[^2]. ```bash # After Restarting IntelliJ IDEA $ intellij-idea --restart ``` #### Configuration Options Available Post-installation Once installed, configuring specific behaviors associated with AllGet can be done under general preferences section accessible again from main menu bar using path similar to before (`File`->`Settings`). Here one finds options pertaining both global level (applying universally across different opened workspaces) alongside per-project customizations ensuring flexibility according personal needs while maintaining consistency throughout multiple environments when required[^3]. --related questions-- 1. What other types of operations does AllGet enhance besides those mentioned? 2. How do I customize keybindings for quicker access to AllGet's features? 3. Can AllGet integrate additional external services beyond what has been described here? 4. Is there documentation detailing best practices for leveraging AllGet effectively in team collaboration scenarios? 5. Are there alternatives comparable to AllGet offering similar enhancements for JetBrains products?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值