java判断软件悬浮窗权限
2023-01-24 09:16:15 最后更新
//Code By xiaoyi
mian.iyu
call(back,"mjava","Window.getAppOps",activity)
tw(back)

window.ijava

import android.app.*;
import android.content.*;
import android.os.*;
import java.lang.reflect.*;
public static boolean getAppOps(Context context) 
{
  try 
  {
    Object object = context.getSystemService("appops");
    if (object == null) 
    {
      return false;
    }
    Class localClass = object.getClass();
    Class[] arrayOfClass = new Class[3];
    arrayOfClass[0] = Integer.TYPE;
    arrayOfClass[1] = Integer.TYPE;
    arrayOfClass[2] = String.class;
    Method method = localClass.getMethod("checkOp", arrayOfClass);
    if (method == null) 
    {
      return false;
    }
    Object[] arrayOfObject1 = new Object[3];
    arrayOfObject1[0] = Integer.valueOf(24);
    arrayOfObject1[1] = Integer.valueOf(Binder.getCallingUid());
    arrayOfObject1[2] = context.getPackageName();
    int m = ((Integer) method.invoke(object, arrayOfObject1)).intValue();
    return m == AppOpsManager.MODE_ALLOWED;
  } catch (Exception ex) 
  {

  }
  return false;
}