判断activity是否显示在界面上
boolean result = false; ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(2).get(0).topActivity; if (cn != null) { if ("com.android.phone.InCallScreen".equals(cn.getClassName())) { result = true; } } return result;
需要加入权限:
<uses-permission android:name="android.permission.GET_TASKS" />