| package com.doumee.lib_coremodel.util; | 
|   | 
| import android.app.AppOpsManager; | 
| import android.content.Context; | 
| import android.content.pm.ApplicationInfo; | 
| import android.os.Build; | 
|   | 
| import androidx.annotation.RequiresApi; | 
| import androidx.core.app.NotificationManagerCompat; | 
|   | 
| import com.doumee.lib_coremodel.http.utils.GsonTools; | 
|   | 
| import java.lang.reflect.Field; | 
| import java.lang.reflect.Method; | 
|   | 
| public class CommonUtils { | 
|   | 
|     //判断该app是否打开了通知 | 
|     /** | 
|      * 可以通过NotificationManagerCompat 中的 areNotificationsEnabled()来判断是否开启通知权限。NotificationManagerCompat 在 android.support.v4.app包中,是API 22.1.0 中加入的。而 areNotificationsEnabled()则是在 API 24.1.0之后加入的。 | 
|      * areNotificationsEnabled 只对 API 19 及以上版本有效,低于API 19 会一直返回true | 
|      * */ | 
|     @RequiresApi(api = Build.VERSION_CODES.KITKAT) | 
|     public static boolean isNotificationEnabled(Context context) { | 
|         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ | 
|             NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); | 
|             boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled(); | 
|             return areNotificationsEnabled; | 
|         } | 
|         String CHECK_OP_NO_THROW = "checkOpNoThrow"; | 
|         String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION"; | 
|         AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); | 
|         ApplicationInfo appInfo = context.getApplicationInfo(); | 
|         String pkg = context.getApplicationContext().getPackageName(); | 
|         int uid = appInfo.uid; | 
|         Class appOpsClass = null; | 
|         /* Context.APP_OPS_MANAGER */ | 
|         try { | 
|             appOpsClass = Class.forName(AppOpsManager.class.getName()); | 
|             Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, | 
|                     String.class); | 
|             Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); | 
|             int value = (Integer) opPostNotificationValue.get(Integer.class); | 
|             return ((Integer) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|         } | 
|         return false; | 
|     } | 
|   | 
|     public static boolean isEquals(Object o1,Object o2){ | 
|         String s1 = GsonTools.changeGsonToJson(o1); | 
|         String s2 = GsonTools.changeGsonToJson(o2); | 
|         return s1.hashCode() == s2.hashCode(); | 
|     } | 
| } |