[英]how can I know whether an android app widget is in background
我不想在進入后台時更新我的應用程序小部件的用戶界面(您看不到它),我怎么知道應用程序小部件在后台?
您無法檢測您的主屏幕小部件當前是否可見。 有一個開放的bug報告請求這個位置 。
充其量,您可以檢查主屏幕(或通常的任何啟動器)是否可見:
public boolean isHomeShowing(){
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ArrayList<string> homeList = new ArrayList<string>();
for(ResolveInfo info : this.getPackageManager().queryIntentActivities(intent, 0)){
homeList.add(info.activityInfo.packageName);
}
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
for (RunningTaskInfo t : am.getRunningTasks(1)) {
if (t != null && t.numRunning > 0) {
ComponentName cn = t.baseActivity;
if (cn == null)
continue;
else
if (homeList.contains(cn.getPackageName())) return true;
}
}
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.