Java tutorial
//package com.java2s; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.provider.Settings; public class Main { @TargetApi(Build.VERSION_CODES.M) public static boolean canDrawOverlays(Context context) { return !isMarshmallowOrHigher() || Settings.canDrawOverlays(context); } private static boolean isMarshmallowOrHigher() { return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; } }