本文整理汇总了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;
}