Advertisement
Guest User

WifiManager.isWifiApEnabled()

a guest
Feb 8th, 2016
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.     private static Method isWifiApEnabledMethod;
  2.  
  3.     public static boolean isWifiApEnabled(WifiManager wifiManager) {
  4.         if (isWifiApEnabledMethod == null) {
  5.             try {
  6.                 isWifiApEnabledMethod = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
  7.                 isWifiApEnabledMethod.setAccessible(true); //in the case of visibility change in future APIs
  8.             } catch (NoSuchMethodException e) {
  9.                 Log.w(TAG, "Can't get method by reflection", e);
  10.             }
  11.         }
  12.  
  13.         if (isWifiApEnabledMethod != null) {
  14.             try {
  15.                 return (Boolean) isWifiApEnabledMethod.invoke(wifiManager);
  16.             } catch (IllegalAccessException e) {
  17.                 Log.e(TAG, "Can't invoke method by reflection", e);
  18.             } catch (InvocationTargetException e) {
  19.                 Log.e(TAG, "Can't invoke method by reflection", e);
  20.             }
  21.         }
  22.  
  23.         return false;
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement