简体   繁体   English

(Android)检测何时启动另一个应用程序/所有应用程序的启动计数

[英](Android) detect when another app is launched / launch count of all app

I would like to get the information about another app last time used , or launch time ,or launch count of another app. 我想获取有关上次使用的另一个应用程序的信息,或启动时间,或另一个应用程序的启动次数。 (Just like the information of usage statistics) (就像使用情况统计信息一样)

Usage statistics information 使用情况统计 信息

I have found some similar question and answer at here. 我在这里找到了类似的问题和答案。 But those doesn't work in android M or android L. 但是这些在android M或android L中不起作用。

Is there some method can get the information what i need?(example If can) 有什么方法可以获取我需要的信息吗(例如,可以)

Thanks. 谢谢。

1 : 1 在此处输入图片说明

1 : 1 在此处输入图片说明

you can get the UsesStats of the top foreground Applications. 您可以获取最UsesStats的前台应用程序的UsesStats but using this the user have rights to Accept or Decline for each app separately. 但使用此功能,用户有权分别为每个应用接受拒绝 getting the permission 获得许可

Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);

and this will return the foreground applications.. 这将返回前台应用程序。

    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.isEmpty()) {
            topPackageName =  mySortedMap.get(mySortedMap.lastKey()).getPackageName();                                   
        }                                       
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:安装其他应用并检测其首次启动时间 - Android: Install another app and detect when it is launched the first time 当另一个应用程序启动/启动时启动/启动 myApp - Start/launch myApp when another app started/launched 如何在 Android 中跟踪应用程序使用情况? 如何检测活动何时启动? - How to Track App Usage in Android? How to detect when an activity is launched? 如何检测来自后台服务或其他应用的Android应用启动 - How to detect launch of an app in Android from a background service or another app 检测哪个应用已在Android中启动 - Detect which app has been launched in android 如何检测是否在Android中启动任何本机应用程序 - How to detect if any native app is launched in android Android小部件启动应用程序并检测未找到的应用程序 - Android widget launch App and detect App Not found 如何确认Android应用是DeepLink启动还是正常启动? - How to confirm whether Android app is launched by DeepLink or normal launch? 仅在重新启动应用程序时如何启动启动屏幕活动? - How to launch splash screen activity only when app is launched afresh? 应用启动时Android 9手机崩溃 - Android 9 phone crashes when app is launched
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM