/** * sdcard是否可读写 * * @return */ public static boolean isSdcardReady() { try { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } catch (Exception e) { LogS.e(TAG, "isSdcardReady had exception!", e); return false; } }
/** * 程序是否在前台运行 * * @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; }