添加权限
***.SYSTEM_ALERT_WINDOW
新建alert.mjava
文件
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
//是否有悬浮窗权限
public static boolean hasAlertWindow(Activity activity){
return Settings.canDrawOverlays(activity);
}
public static void requestAlertWindow(Activity activity){
try {
String packageName = activity.getPackageName();
activity.startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName)));
}catch (Exception e){}
}
iyu调用
//判断是否已开启悬浮窗
call(isOpen,"mjava","alert.hasAlertWindow",activity)
//如果没有权限可以使用这条代码,需要自己加判断
call(null,"mjava","alert.requestAlertWindow",activity)
网友评论