Java Code Examples for android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_FOREGROUND

The following examples show how to use android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_FOREGROUND . 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: StopListennerActivity.java    From AssistantBySDK with Apache License 2.0 8 votes vote down vote up
private boolean isAppOnForeground() { 
    ActivityManager aManager=((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE));
       List<RunningAppProcessInfo> appProcesses = aManager.getRunningAppProcesses(); 
       if (appProcesses == null) return false; 
       for (RunningAppProcessInfo appProcess : appProcesses) { 
           if (appProcess.processName.equals(getPackageName())){
           	    Log.e("StopListennerActivity", "appProcess.importance="+appProcess.importance);
           	   // inRunningTasks(aManager);
           	    if(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { 
           			return true; 
           		}else{
           			return false;
           		}
           } 
       } 
       return false; 
}
 
Example 2
Source File: RNPushNotificationListenerService.java    From react-native-push-notification-CE with MIT License 6 votes vote down vote up
private boolean isApplicationInForeground() {
    ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    if (processInfos != null) {
        for (RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(getApplication().getPackageName())) {
                if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    for (String d : processInfo.pkgList) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: NetUtils.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
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())) {
			/*
			 * BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000
			 * PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
			 */
			Log.i(context.getPackageName(), "此appimportace =" + appProcess.importance
					+ ",context.getClass().getName()=" + context.getClass().getName());
			if (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				Log.i(context.getPackageName(), "处于后台" + appProcess.processName);
				return true;
			} else {
				Log.i(context.getPackageName(), "处于前台" + appProcess.processName);
				return false;
			}
		}
	}
	return false;
}
 
Example 4
Source File: CheckUtil.java    From ZhihuDaily with MIT License 6 votes vote down vote up
/** APP is not runing true:false  */
public static boolean isBackground(Context context) {
       ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
       List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
       for (RunningAppProcessInfo appProcess : appProcesses) {
           //判断所有的app进程,报名是否等于该app
       	if (appProcess.processName.equals(context.getPackageName())) {
               if (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                   return true; //"处于后台"
               } else {
                   return false;//"处于前台"
               }
           }
       }
       return false;
   }
 
Example 5
Source File: PackageManagerUtil.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * 程序是否在前台
 * @deprecated 注:如果对于APP启动后有常驻Service,也判断为了前台(也不准)
 * @param context
 */
@Deprecated
public static boolean isAppOnForeground(final Context context) {
    if (context == null) {
        return false;
    }
    Context appContext = context.getApplicationContext();
    ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager == null) {
        return false;
    }
    String packageName = appContext.getPackageName();
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses != null) {
        for (RunningAppProcessInfo appProcess : appProcesses) {
            // The name of the process that this object is associated with.
            if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                return true;
            }
        }
    }
    return false;
}
 
Example 6
Source File: NetUtils.java    From gokit-android with MIT License 6 votes vote down vote up
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())) {
			/*
			 * BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000
			 * PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
			 */
			Log.i(context.getPackageName(), "此appimportace =" + appProcess.importance
					+ ",context.getClass().getName()=" + context.getClass().getName());
			if (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				Log.i(context.getPackageName(), "处于后台" + appProcess.processName);
				return true;
			} else {
				Log.i(context.getPackageName(), "处于前台" + appProcess.processName);
				return false;
			}
		}
	}
	return false;
}
 
Example 7
Source File: ServiceHelper.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
public boolean isAppOnForeground() {
    // Returns a list of application processes that are running on the
    // device
    String packageName = context.getPackageName();
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null)
        return false;
    for (RunningAppProcessInfo appProcess : appProcesses) {
        // importance:
        // The relative importance level that the system places
        // on this process.
        // May be one of IMPORTANCE_FOREGROUND, IMPORTANCE_VISIBLE,
        // IMPORTANCE_SERVICE, IMPORTANCE_BACKGROUND, or IMPORTANCE_EMPTY.
        // These constants are numbered so that "more important" values are
        // always smaller than "less important" values.
        // processName:
        // The name of the process that this object is associated with.
        if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: AndroidUtil.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
/**
 * 程序是否在前台运行
 * 
 * @return
 */
public static boolean isAppOnForeground(Context context) {
	try {
		ActivityManager activityManager = (ActivityManager) context
				.getApplicationContext().getSystemService(
						Context.ACTIVITY_SERVICE);
		String packageName = context.getPackageName();
		List<RunningAppProcessInfo> appProcesses = activityManager
				.getRunningAppProcesses();
		if (appProcesses == null) {
			return false;
		}
		for (RunningAppProcessInfo appProcess : appProcesses) {
			// The name of the process that this object is associated with.
			if (appProcess.processName.equals(packageName)
					&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				return true;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		LogS.e(TAG, "isAppOnForeground exception!", e);
	}
	return false;
}
 
Example 9
Source File: AppUtils.java    From AndroidWear-OpenWear with MIT License 5 votes vote down vote up
public static boolean isMyAppInForeground(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())) {
            return appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
        }
    }
    return true;
}
 
Example 10
Source File: ActivityUtils.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if this application is foreground
 * 
 * @param context Context to be examined
 * @return true if this application is running on the top; false otherwise
 */
public static boolean isContextForeground(Context context) {

	ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
	int pid = getPid();
	for (RunningAppProcessInfo appProcess : appProcesses) {
		if (appProcess.pid == pid) {
			return appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
		}
	}
	return false;
}
 
Example 11
Source File: RNReceivedMessageHandler.java    From react-native-push-notification with MIT License 5 votes vote down vote up
private boolean isApplicationInForeground() {
    ActivityManager activityManager = (ActivityManager) mFirebaseMessagingService.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    if (processInfos != null) {
        for (RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(mFirebaseMessagingService.getPackageName())
                && processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND
                && processInfo.pkgList.length > 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source File: RNPushNotificationHelper.java    From react-native-push-notification with MIT License 5 votes vote down vote up
private boolean isApplicationInForeground(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    if (processInfos != null) {
        for (RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(context.getPackageName())
                && processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND
                && processInfo.pkgList.length > 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example 13
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 14
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 15
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 16
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 17
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 18
Source File: AppsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
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 19
Source File: ProcessFragment.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
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 20
Source File: MyActivityManagerService.java    From DroidPlugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
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) {
            //前台进程。
        }
    }

}