/**
* 是否打开通知栏开关
* @param context
* @return
*/
public static boolean isNotificationEnabled(Context context) {
try {
//4.3以上版本能获取到通知栏状态
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){//api19+
return NotificationManagerCompat.from(ftalkApp.appContext()).areNotificationsEnabled();
}else if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
{
Object localObject = context
.getSystemService(Context.APP_OPS_SERVICE);
Class localClass = localObject.getClass();
Class[] arrayOfClass = new Class[3];
arrayOfClass[0] = Integer.TYPE;
arrayOfClass[1] = Integer.TYPE;
arrayOfClass[2] = String.class;
Method localMethod = localClass.getMethod(CHECK_OP_NO_THROW,arrayOfClass);
Field opPostNotificationValue = localClass.getDeclaredField(OP_POST_NOTIFICATION);
int value = (Integer) opPostNotificationValue.get(Integer.class);
Object[] arrayOfObject = new Object[3];
arrayOfObject[0] = value;
arrayOfObject[1] = Integer.valueOf(Binder.getCallingUid());
arrayOfObject[2] = context.getPackageName();
int j = ((Integer) localMethod.invoke(localObject,
arrayOfObject)).intValue();
return j == 0;
}else {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
网友评论