Java tutorial
//package com.java2s; /* BleUtils Copyright (c) 2015 NTT DOCOMO,INC. Released under the MIT license http://opensource.org/licenses/mit-license.php */ import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; public class Main { /** * Defined the permission of BLE scan. */ public static final String[] BLE_PERMISSIONS = new String[] { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }; /** * Checks whether permission allow by user. * @param context context of application * @return Returns true if permission allow, otherwise false */ public static boolean isBLEPermission(final Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } else { boolean result = true; for (int i = 0; i < BLE_PERMISSIONS.length; i++) { if (context.checkSelfPermission(BLE_PERMISSIONS[i]) != PackageManager.PERMISSION_GRANTED) { result = false; } } return result; } } }