本文整理匯總了Java中android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的典型用法代碼示例。如果您正苦於以下問題:Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的具體用法?Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND怎麽用?Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.app.ActivityManager.RunningAppProcessInfo
的用法示例。
在下文中一共展示了RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isAppOnForeground
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;
}
示例2: isBackground
/**
* 根據包名判斷應用在前台還是後台
*
* @param context
* @return
*/
public static boolean isBackground(Context context, String packageName) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(packageName)) {
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
Log.i("前台", appProcess.processName);
return false;
} else {
Log.i("後台", appProcess.processName);
return true;
}
}
}
return true;
}
示例3: isAppOnForeground
/**
* 判斷應用是否在前台顯示
*
* @param context 上下文
* @param packageName 包名
* @return 返回true表示在前台顯示
*/
public static boolean isAppOnForeground(Context context, String packageName) {
if (packageName == null || context == null) {
return false;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(packageName)
&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return true;
}
}
return false;
}
示例4: isAppOnForeground
/**
* 程序是否在前台運行
*
* @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;
}
示例5: applicationIsRunning
private boolean applicationIsRunning(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo processInfo : processInfos) {
if (processInfo.processName.equals(context.getApplicationContext().getPackageName())) {
if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String d: processInfo.pkgList) {
Log.v("ReactSystemNotification", "NotificationEventReceiver: ok: " + d);
return true;
}
}
}
}
} else {
List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
示例6: isAppOnForeground
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;
}
示例7: isBackground
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;
}
示例8: isActivityForeground
/**
* check FM is foreground or background
*/
public boolean isActivityForeground() {
boolean isForeground = true;
List<RunningAppProcessInfo> appProcessInfos = mActivityManager.getRunningAppProcesses();
for (RunningAppProcessInfo appProcessInfo : appProcessInfos) {
if (appProcessInfo.processName.equals(mContext.getPackageName())) {
int importance = appProcessInfo.importance;
Log.d(TAG, "isActivityForeground importance:" + importance);
if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND ||
importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
Log.d(TAG, "isActivityForeground is foreground");
isForeground = true;
} else {
Log.d(TAG, "isActivityForeground is background");
isForeground = false;
}
break;
}
}
Log.d(TAG, "isActivityForeground return " + isForeground);
return isForeground;
}
示例9: _IsAppOnForeground
private boolean _IsAppOnForeground()
{
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().getPackageName();
List<RunningAppProcessInfo> appProcesses = activityManager
.getRunningAppProcesses();
if (appProcesses == null)
return false;
for (RunningAppProcessInfo appProcess : appProcesses)
{
if (appProcess.processName.equals(packageName)
&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
{
return true;
}
}
return false;
}
示例10: isAppInForeground
private boolean isAppInForeground(Context context)
{
ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses != null)
{
final String packageName = context.getPackageName();
for (RunningAppProcessInfo appProcess : appProcesses)
{
Log.i("GCMExtensionProcessList", "running process name = " + appProcess.processName);
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName))
{
return true;
}
}
}
return false;
}
示例11: isAppOnForeground
/**
* 程序是否在前台運行
*
* @return
*/
public boolean isAppOnForeground() {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().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;
}
}
return false;
}
示例12: isApplicationInForeground
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;
}
示例13: isAppOnForeground
private boolean isAppOnForeground() {
// Returns a list of application processes that are running on the
// device
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;
}
示例14: isAppOnForeground
/**
* 判斷應用是否在前台
* @return
*/
public boolean isAppOnForeground() {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().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;
}
}
return false;
}
示例15: isAppOnForeground
public boolean isAppOnForeground() {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().getPackageName();
List<RunningAppProcessInfo> appProcesses = activityManager
.getRunningAppProcesses();
if (appProcesses == null)
return false;
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(packageName)
&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return true;
}
}
return false;
}