當前位置: 首頁>>代碼示例>>Java>>正文


Java UsageStats.add方法代碼示例

本文整理匯總了Java中android.app.usage.UsageStats.add方法的典型用法代碼示例。如果您正苦於以下問題:Java UsageStats.add方法的具體用法?Java UsageStats.add怎麽用?Java UsageStats.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.usage.UsageStats的用法示例。


在下文中一共展示了UsageStats.add方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
        UsageStatsAdapter() {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, -1);

            //System.out.println("**Today****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
            //System.out.println("**Today**System.currentTimeMillis()**** " + System.currentTimeMillis());

            //final List<UsageStats>
            stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
                    cal.getTimeInMillis(), System.currentTimeMillis());

            System.out.println("---------------------" + stats);

            for (UsageStats usg : stats) {
              /*  System.out.println("***stats count "+stats.size());
                System.out.println("********************");
                System.out.println("" + usg.getPackageName());
//              System.out.println("First time: " + usg.getFirstTimeStamp());*/


                //System.out.println("Last time :" + usg.getLastTimeStamp());
                // System.out.println("Total Time: " + usg.getTotalTimeInForeground());
                //System.out.println(usg.getLastTimeUsed());


            }
            if (stats == null) {
                return;
            }

            ArrayMap<String, UsageStats> map = new ArrayMap<>();

            final int statCount = stats.size();
            for (int i = 0; i < statCount; i++) {
                final UsageStats pkgStats = stats.get(i);
                // load application labels for each application
                try {
                    ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
                    String label = appInfo.loadLabel(mPm).toString();
                    mAppLabelMap.put(pkgStats.getPackageName(), label);

                    UsageStats existingStats = map.get(pkgStats.getPackageName());

                    /*for(int j=0;j<getSavedApps.size();j++){
                        System.out.println("**********4");
                        System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
                        System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/

                    if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
                        //System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
                        if (existingStats == null) {
                            map.put(pkgStats.getPackageName(), pkgStats);
                        } else {
                            existingStats.add(pkgStats);
                        }
                    } else System.out.println("****no match found");

                } catch (PackageManager.NameNotFoundException e) {
                    // This package may be gone.
                }
            }
            mPackageStats.addAll(map.values());

            // Sort list
            mAppLabelComparator = new AppNameComparator(mAppLabelMap);
            sortList();
        }
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:69,代碼來源:AppService.java

示例2: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
        UsageStatsAdapter() {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_WEEK, -1);

            System.out.println("**Today****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
            System.out.println("**Today**System.currentTimeMillis()**** " + System.currentTimeMillis());

            //final List<UsageStats>
            stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, cal.getTimeInMillis(), System.currentTimeMillis());

            System.out.println("---------------------" + stats);

            for (UsageStats usg : stats) {
              /*  System.out.println("***stats count "+stats.size());
                System.out.println("********************");
                System.out.println("" + usg.getPackageName());
//              System.out.println("First time: " + usg.getFirstTimeStamp());*/


                //System.out.println("Last time :" + usg.getLastTimeStamp());
                // System.out.println("Total Time: " + usg.getTotalTimeInForeground());
                //System.out.println(usg.getLastTimeUsed());
                System.out.println("********************");

            }
            if (stats == null) {
                return;
            }

            ArrayMap<String, UsageStats> map = new ArrayMap<>();

            final int statCount = stats.size();
            for (int i = 0; i < statCount; i++) {
                final UsageStats pkgStats = stats.get(i);
                // load application labels for each application
                try {
                    ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
                    String label = appInfo.loadLabel(mPm).toString();
                    mAppLabelMap.put(pkgStats.getPackageName(), label);

                    UsageStats existingStats = map.get(pkgStats.getPackageName());

                    /*for(int j=0;j<getSavedApps.size();j++){
                        System.out.println("**********4");
                        System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
                        System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/

                    if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
                        //System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
                        if (existingStats == null) {
                            map.put(pkgStats.getPackageName(), pkgStats);
                        } else {
                            existingStats.add(pkgStats);
                        }
                    } else System.out.println("****no match found");

                } catch (PackageManager.NameNotFoundException e) {
                    // This package may be gone.
                }
            }
            mPackageStats.addAll(map.values());

            // Sort list
            mAppLabelComparator = new AppNameComparator(mAppLabelMap);
            sortList();
        }
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:68,代碼來源:Today.java

示例3: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
        UsageStatsAdapter() {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_WEEK, -1);

            System.out.println("**Yday****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
            System.out.println("**Yday**System.currentTimeMillis()**** " + System.currentTimeMillis());

            //final List<UsageStats>
            stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
                    cal.getTimeInMillis(), System.currentTimeMillis());

            //System.out.println("---------------------"+stats);
            for (UsageStats usg : stats) {
//                System.out.println("***stats count "+stats.size());
//                System.out.println("********************");
//                System.out.println("" + usg.getPackageName());
//                System.out.println("First time: " + usg.getFirstTimeStamp());
//                System.out.println("Last time :" + usg.getLastTimeStamp());
//                System.out.println("Total Time: " + usg.getTotalTimeInForeground());
//                System.out.println(usg.getLastTimeUsed());
//                System.out.println("********************");
                //mPieChart.addPieSlice(new PieModel("", usg.getTotalTimeInForeground(), Color.parseColor(color)));

            }

            //mPieChart.startAnimation();

            if (stats == null) {
                return;
            }

            ArrayMap<String, UsageStats> map = new ArrayMap<>();

            final int statCount = stats.size();
            for (int i = 0; i < statCount; i++) {
                final UsageStats pkgStats = stats.get(i);
                // load application labels for each application
                try {
                    ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
                    String label = appInfo.loadLabel(mPm).toString();
                    mAppLabelMap.put(pkgStats.getPackageName(), label);

                    UsageStats existingStats = map.get(pkgStats.getPackageName());

                    /*for(int j=0;j<getSavedApps.size();j++){
                        System.out.println("**********4");
                        System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
                        System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/

                    if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
                        //System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
                        if (existingStats == null) {
                            map.put(pkgStats.getPackageName(), pkgStats);
                        } else {
                            existingStats.add(pkgStats);
                        }
                    } else System.out.println("****no match found");
                    //}


                    /*if (existingStats == null) {
                        map.put(pkgStats.getPackageName(), pkgStats);
                    } else {
                        existingStats.add(pkgStats);
                    }*/

                } catch (PackageManager.NameNotFoundException e) {
                    // This package may be gone.
                }
            }
            mPackageStats.addAll(map.values());

            // Sort list
            mAppLabelComparator = new AppNameComparator(mAppLabelMap);
            sortList();
        }
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:78,代碼來源:Yesterday.java

示例4: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
        UsageStatsAdapter() {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, -5);

            System.out.println("**Today****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
            System.out.println("**Today**System.currentTimeMillis()**** " + System.currentTimeMillis());

            //final List<UsageStats>
            stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_MONTHLY,
                    cal.getTimeInMillis(), System.currentTimeMillis());

            System.out.println("---------------------" + stats);
            for (UsageStats usg : stats) {
//                System.out.println("***stats count "+stats.size());
//                System.out.println("********************");
//                System.out.println("" + usg.getPackageName());
//                System.out.println("First time: " + usg.getFirstTimeStamp());
//                System.out.println("Last time :" + usg.getLastTimeStamp());
//                System.out.println("Total Time: " + usg.getTotalTimeInForeground());
//                System.out.println(usg.getLastTimeUsed());
//                System.out.println("********************");
                //mPieChart.addPieSlice(new PieModel("", usg.getTotalTimeInForeground(), Color.parseColor(color)));

            }

            //mPieChart.startAnimation();

            if (stats == null) {
                return;
            }

            ArrayMap<String, UsageStats> map = new ArrayMap<>();

            final int statCount = stats.size();
            for (int i = 0; i < statCount; i++) {
                final UsageStats pkgStats = stats.get(i);
                // load application labels for each application
                try {
                    ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
                    String label = appInfo.loadLabel(mPm).toString();
                    mAppLabelMap.put(pkgStats.getPackageName(), label);

                    UsageStats existingStats = map.get(pkgStats.getPackageName());

                    /*for(int j=0;j<getSavedApps.size();j++){
                        System.out.println("**********4");
                        System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
                        System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/

                    if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
                        //System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
                        if (existingStats == null) {
                            map.put(pkgStats.getPackageName(), pkgStats);
                        } else {
                            existingStats.add(pkgStats);
                        }
                    } else System.out.println("****no match found");
                    //}


                    /*if (existingStats == null) {
                        map.put(pkgStats.getPackageName(), pkgStats);
                    } else {
                        existingStats.add(pkgStats);
                    }*/

                } catch (PackageManager.NameNotFoundException e) {
                    // This package may be gone.
                }
            }
            mPackageStats.addAll(map.values());

            // Sort list
            //mAppLabelComparator = new AppNameComparator(mAppLabelMap);
            //sortList();
        }
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:78,代碼來源:LastMonth.java

示例5: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
UsageStatsAdapter() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -5);

    final List<UsageStats> stats =
            mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_MONTHLY,
                    cal.getTimeInMillis(), System.currentTimeMillis());

    for (UsageStats usg : stats) {
        System.out.println("---------------------");
        System.out.println("" + usg.getPackageName());
        System.out.println("First time: " + usg.getFirstTimeStamp());
        System.out.println("Last time :" + usg.getLastTimeStamp());
        System.out.println("Total Time: " + usg.getTotalTimeInForeground());
        System.out.println(usg.getLastTimeUsed());
        System.out.println("---------------------");

    }
    if (stats == null) {
        return;
    }

    ArrayMap<String, UsageStats> map = new ArrayMap<>();
    final int statCount = stats.size();
    for (int i = 0; i < statCount; i++) {
        final UsageStats pkgStats = stats.get(i);

        // load application labels for each application
        try {
            ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
            String label = appInfo.loadLabel(mPm).toString();
            mAppLabelMap.put(pkgStats.getPackageName(), label);

            UsageStats existingStats =
                    map.get(pkgStats.getPackageName());
            if (existingStats == null) {
                map.put(pkgStats.getPackageName(), pkgStats);
            } else {
                existingStats.add(pkgStats);
            }

        } catch (PackageManager.NameNotFoundException e) {
            // This package may be gone.
        }
    }
    mPackageStats.addAll(map.values());

    // Sort list
    mAppLabelComparator = new AppNameComparator(mAppLabelMap);
    sortList();
}
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:53,代碼來源:Sorting.java

示例6: UsageStatsAdapter

import android.app.usage.UsageStats; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
        UsageStatsAdapter() {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, -5);

            System.out.println("**Today****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
            System.out.println("**Today**System.currentTimeMillis()**** " + System.currentTimeMillis());

            //final List<UsageStats>
            stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_WEEKLY,
                    cal.getTimeInMillis(), System.currentTimeMillis());

            System.out.println("---------------------" + stats);
            for (UsageStats usg : stats) {
//                System.out.println("***stats count "+stats.size());
//                System.out.println("********************");
//                System.out.println("" + usg.getPackageName());
//                System.out.println("First time: " + usg.getFirstTimeStamp());
//                System.out.println("Last time :" + usg.getLastTimeStamp());
//                System.out.println("Total Time: " + usg.getTotalTimeInForeground());
//                System.out.println(usg.getLastTimeUsed());
//                System.out.println("********************");
                //mPieChart.addPieSlice(new PieModel("", usg.getTotalTimeInForeground(), Color.parseColor(color)));

            }

            //mPieChart.startAnimation();

            if (stats == null) {
                return;
            }

            ArrayMap<String, UsageStats> map = new ArrayMap<>();

            final int statCount = stats.size();
            for (int i = 0; i < statCount; i++) {
                final UsageStats pkgStats = stats.get(i);
                // load application labels for each application
                try {
                    ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
                    String label = appInfo.loadLabel(mPm).toString();
                    mAppLabelMap.put(pkgStats.getPackageName(), label);

                    UsageStats existingStats = map.get(pkgStats.getPackageName());

                    /*for(int j=0;j<getSavedApps.size();j++){
                        System.out.println("**********4");
                        System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
                        System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/

                    if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
                        //System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
                        if (existingStats == null) {
                            map.put(pkgStats.getPackageName(), pkgStats);
                        } else {
                            existingStats.add(pkgStats);
                        }
                    } else System.out.println("****no match found");
                    //}


                    /*if (existingStats == null) {
                        map.put(pkgStats.getPackageName(), pkgStats);
                    } else {
                        existingStats.add(pkgStats);
                    }*/

                } catch (PackageManager.NameNotFoundException e) {
                    // This package may be gone.
                }
            }
            mPackageStats.addAll(map.values());

            // Sort list
            //mAppLabelComparator = new AppNameComparator(mAppLabelMap);
            //sortList();
        }
 
開發者ID:spate141,項目名稱:App-Monitor,代碼行數:78,代碼來源:LastWeek.java


注:本文中的android.app.usage.UsageStats.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。