Java Code Examples for android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_BACKGROUND
The following examples show how to use
android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_BACKGROUND .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemUtils.java From VideoMeeting with Apache License 2.0 | 6 votes |
/** * 判断当前应用程序是否后台运行 */ public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { // 后台运行 return true; } else { // 前台运行 return false; } } } return false; }
Example 2
Source File: SystemTool.java From Lay-s with MIT License | 6 votes |
/** * 判断当前应用程序是否后台运行 */ public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { // 后台运行 return true; } else { // 前台运行 return false; } } } return false; }
Example 3
Source File: ProcessFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
private void bind(final int position) { final ProcessInfo pi = lpinfo.get(position); cbx.setTag(pi); more.setTag(pi); name.setText(pi.label); attr.setText(pi.packageName); items.setText(Util.nf.format(pi.size) + " B"); int importance = pi.status; if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { type.setText("Foreground"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE) { type.setText("Foreground Service"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { type.setText("Background"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) { type.setText("Visible"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) { type.setText("Perceptible"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) { type.setText("Service"); } else if (importance == 150) {//}RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING) { type.setText("Sleep"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_GONE) { type.setText("Gone"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) { type.setText("Can't save state"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) { type.setText("Empty"); } try { image.setImageDrawable(pk.getApplicationIcon(pi.packageName)); } catch (NameNotFoundException e) { image.setImageResource(R.drawable.ic_doc_apk); } final boolean checked = selectedInList1.contains(pi.packageName); if (checked) { ll.setBackgroundColor(Constants.IN_DATA_SOURCE_2); cbx.setSelected(true); cbx.setImageResource(R.drawable.ic_accept); } else if (selectedInList1.size() > 0) { ll.setBackgroundColor(Constants.BASE_BACKGROUND); cbx.setSelected(false); cbx.setImageResource(R.drawable.ready); } else { ll.setBackgroundResource(R.drawable.ripple); cbx.setSelected(false); cbx.setImageResource(R.drawable.dot); } }
Example 4
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 5
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromService(MatrixCursor result, String docId, RunningServiceInfo processInfo, String query ) { String process = processInfo.process; final String packageName = processInfo.process; process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, processInfo.lastActivityTime); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 6
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 7
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromService(MatrixCursor result, String docId, RunningServiceInfo processInfo, String query ) { String process = processInfo.process; final String packageName = processInfo.process; process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, processInfo.lastActivityTime); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 8
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 9
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromService(MatrixCursor result, String docId, RunningServiceInfo processInfo, String query ) { String process = processInfo.process; final String packageName = processInfo.process; process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, processInfo.lastActivityTime); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example 10
Source File: MyActivityManagerService.java From DroidPlugin with GNU Lesser General Public License v3.0 | 4 votes |
private void runProcessGC() { if (mHostContext == null) { return; } ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return; } List<RunningAppProcessInfo> infos = am.getRunningAppProcesses(); List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>(); if (infos == null || infos.size() < 0) { return; } List<String> pns = mStaticProcessList.getOtherProcessNames(); pns.add(mHostContext.getPackageName()); for (RunningAppProcessInfo info : infos) { if (info.uid == android.os.Process.myUid() && info.pid != android.os.Process.myPid() && !pns.contains(info.processName) && mRunningProcessList.isPlugin(info.pid) && !mRunningProcessList.isPersistentApplication(info.pid) /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/) { myInfos.add(info); } } Collections.sort(myInfos, sProcessComparator); for (RunningAppProcessInfo myInfo : myInfos) { if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) { doGc(myInfo); } /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) { //杀死进程,不能保存状态。但是关我什么事? }*/ else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) { //杀死进程 } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) { //看得见 } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { //前台进程。 } } }