判断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" />

posted @ 2015-01-07 16:37  TealerProg  Views(3055)  Comments(0Edit  收藏  举报