List of usage examples for android.content Context checkCallingPermission
@CheckResult(suggest = "#enforceCallingPermission(String,String)") @PackageManager.PermissionResult public abstract int checkCallingPermission(@NonNull String permission);
From source file:Main.java
private static boolean hasExternalStoragePermission(Context context) { int permission = context.checkCallingPermission(EXTERNAL_STORAGE_PERMISSION); return permission == PackageManager.PERMISSION_GRANTED; }
From source file:org.cocos2dx.lib.CCUtils.java
public static String getMacAddress() { String mac = ""; Context ctx = Cocos2dxActivity.getContext(); // first, try to get mac from wifi manager if (ctx.checkCallingPermission(permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED) { WifiManager wifi = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); mac = info.getMacAddress();/*ww w. j a va 2 s.c o m*/ } // if failed, try from network interface api if (TextUtils.isEmpty(mac)) { if (Build.VERSION.SDK_INT >= 9) { try { NetworkInterface ne = NetworkInterface .getByInetAddress(InetAddress.getByName(getLocalIpAddress())); byte[] b = ne.getHardwareAddress(); mac = byte2Hex(b); } catch (Exception e) { e.printStackTrace(); } } } // if failed, use fake if (TextUtils.isEmpty(mac)) { mac = "00:00:00:00:00:00"; } // return return mac; }