List of usage examples for android.content.pm ApplicationInfo ApplicationInfo
public ApplicationInfo()
From source file:Main.java
/** * Create and populate an {@link android.content.pm.ApplicationInfo} object that describes an * installed app./*w w w . j a v a 2 s .c o m*/ * * @param uid The app's uid * @param packageName The app's package name. * @param flags Flags describing the app. See {@link android.content.pm.ApplicationInfo#flags} * for possible values. * @param targetSdkVersion The app's target SDK version * * @see android.content.pm.ApplicationInfo */ public static ApplicationInfo buildInfo(int uid, String packageName, int flags, int targetSdkVersion) { final ApplicationInfo info = new ApplicationInfo(); info.uid = uid; info.packageName = packageName; info.flags = flags; info.targetSdkVersion = targetSdkVersion; return info; }
From source file:com.rui.ruitime.AppUsageStatisticsFragment.java
/** * Updates the {@link #mRecyclerView} with the list of {@link UsageStats} passed as an argument. * * @param usageStatsList A list of {@link UsageStats} from which update the * {@link #mRecyclerView}. *//*w w w . j a v a2 s.c o m*/ //VisibleForTesting void updateAppsList(List<UsageStats> usageStatsList, int modeOfSorting) { customUsageStatsList.clear(); PackageManager packageManager = getActivity().getPackageManager(); for (int i = 0; i < usageStatsList.size(); i++) { CustomAppUsageStats customUsageStats = new CustomAppUsageStats(); ApplicationInfo appInfo = new ApplicationInfo(); customUsageStats.usageStats = usageStatsList.get(i); try { Drawable appIcon = getActivity().getPackageManager() .getApplicationIcon(customUsageStats.usageStats.getPackageName()); customUsageStats.appIcon = appIcon; } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, String.format("App Icon is not found for %s", customUsageStats.usageStats.getPackageName())); customUsageStats.appIcon = getActivity().getDrawable(R.drawable.ic_default_app_launcher); } try { appInfo = packageManager.getApplicationInfo(customUsageStats.usageStats.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, String.format("App Name is not interpreted for %s", customUsageStats.usageStats.getPackageName())); } customUsageStats.appName = (String) (appInfo != null ? packageManager.getApplicationLabel(appInfo) : "Unknown"); int[] statsDuration = { 0, 0, 0 }; long lastTimeUsed = customUsageStats.usageStats.getLastTimeUsed(); DateFormat df = new SimpleDateFormat(); customUsageStats.lastUsedTimestampString = df.format(new Date(lastTimeUsed)); long totalDurationUsed = (long) (customUsageStats.usageStats.getTotalTimeInForeground() / 1000.0D); statsDuration[0] = (int) (totalDurationUsed / 3600); statsDuration[1] = (int) ((totalDurationUsed - statsDuration[0] * 3600) / 60); statsDuration[2] = (int) ((totalDurationUsed - statsDuration[0] * 3600 - statsDuration[1] * 60)); customUsageStats.totalUsedDurationString = ((statsDuration[0] > 0) ? statsDuration[0] + "h " : "") + ((statsDuration[1] > 0) ? statsDuration[1] + "m " : "") + ((statsDuration[2] > 0) ? statsDuration[2] + "s " : "1s"); customUsageStatsList.add(customUsageStats); } if (modeOfSorting == 0) { Collections.sort(customUsageStatsList, new TotalDurationUsedComparatorDesc()); } else if (modeOfSorting == 1) { Collections.sort(customUsageStatsList, new AlphabeticalComparatorDesc()); } mUsageListAdapter.setCustomUsageStatsList(customUsageStatsList); mUsageListAdapter.notifyDataSetChanged(); mRecyclerView.scrollToPosition(0); }