List of usage examples for android.net.wifi WifiManager getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
private static boolean isWifiApEnabled(WifiManager wifiManager) { try {/*from w w w. jav a 2s . c o m*/ Method method = wifiManager.getClass().getMethod("isWifiApEnabled"); method.setAccessible(true); return (Boolean) method.invoke(wifiManager); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static boolean disableAP(Context context, String ntId, String password) throws Exception { boolean apstatus = false; WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); Method[] wmMethods = wifiManager.getClass().getDeclaredMethods(); //Get all declared methods in WifiManager class for (Method method : wmMethods) { if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = ntId;//from w ww. ja va 2 s . c o m netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); netConfig.preSharedKey = password; netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); apstatus = (Boolean) method.invoke(wifiManager, netConfig, false); } } return apstatus; }
From source file:Main.java
private static void closeWifiAp(WifiManager wifiManager) { if (isWifiApEnabled(wifiManager)) { try {//from w w w .j ava 2 s.com Method method = wifiManager.getClass().getMethod("getWifiApConfiguration"); method.setAccessible(true); WifiConfiguration config = (WifiConfiguration) method.invoke(wifiManager); Method method2 = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method2.invoke(wifiManager, config, false); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
public static void createWifiAccessPoint(Context context, String ntId, String password) { try {/*from ww w . j a va 2s . c o m*/ WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(false); } Method[] wmMethods = wifiManager.getClass().getDeclaredMethods(); //Get all declared methods in WifiManager class for (Method method : wmMethods) { if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = ntId; netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); netConfig.preSharedKey = password; netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); try { boolean apstatus = (Boolean) method.invoke(wifiManager, netConfig, true); for (Method isWifiApEnabledmethod : wmMethods) { if (isWifiApEnabledmethod.getName().equals("isWifiApEnabled")) { while (!(Boolean) isWifiApEnabledmethod.invoke(wifiManager)) { } ; for (Method method1 : wmMethods) { if (method1.getName().equals("getWifiApState")) { int apstate; apstate = (Integer) method1.invoke(wifiManager); } } } } if (apstatus) { Log.d("better", "Access Point Created"); } else { Log.d("better", "Failed to create Access Point!"); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:dev.ukanth.ufirewall.InterfaceTracker.java
private static void getTetherStatus(Context context, InterfaceDetails d) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); Method[] wmMethods = wifi.getClass().getDeclaredMethods(); d.isTethered = false;//from ww w . j a v a 2 s . co m d.tetherStatusKnown = false; for (Method method : wmMethods) { if (method.getName().equals("isWifiApEnabled")) { try { d.isTethered = ((Boolean) method.invoke(wifi)).booleanValue(); d.tetherStatusKnown = true; Log.d(TAG, "isWifiApEnabled is " + d.isTethered); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.example.prasadnr.traquad.TraQuad.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tra_quad); ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); Builder alert = new AlertDialog.Builder(TraQuad.this); WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); Method[] wmMethods = managerWifi.getClass().getDeclaredMethods(); for (Method method : wmMethods) { if (method.getName().equals("isWifiApEnabled")) { try { isWifiAPenabled = (boolean) method.invoke(managerWifi); } catch (IllegalArgumentException e) { e.printStackTrace();/*from w ww .j av a2s. co m*/ } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } final ProgressDialog pDialog; MediaController mediaController = new MediaController(this); pDialog = new ProgressDialog(TraQuad.this); pDialog.setTitle("TraQuad app (Connecting...)"); pDialog.setMessage("Buffering...Please wait..."); pDialog.setCancelable(true); if (!isWifiAPenabled) { alert.setTitle("WiFi Hotspot Settings"); alert.setMessage("Can you please connect WiFi-hotspot?"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { irritation = true; startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); pDialog.show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Dismiss AlertDialog pDialog.show(); Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show(); } }); alert.setCancelable(false); AlertDialog alertDialog = alert.create(); alertDialog.show(); } WebView webView = (WebView) findViewById(R.id.webView); if (irritation == true | isWifiAPenabled) { pDialog.show(); } mediaController.setAnchorView(webView); mediaController.setVisibility(View.GONE); extra = getIntent().getStringExtra("VideosId"); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setPluginState(WebSettings.PluginState.ON); final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); final String IPaddressNew = globalVariable.getIP(); final String httpString = "http://"; final String commandPort = String.valueOf(1500); final String streamPort = String.valueOf(8080); final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort; final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort; TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter); try { webView.loadUrl(IPaddressStream); } catch (Exception e) { Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show(); } webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { pDialog.dismiss(); } }); final Button switchact = (Button) findViewById(R.id.btn2); switchact.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent act1 = new Intent(view.getContext(), Joypad.class); startActivity(act1); } }); final Button hometraquad = (Button) findViewById(R.id.button5); hometraquad.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class); startActivity(acthometraquad); } }); }
From source file:com.cubic9.android.droidglove.Main.java
/** * detect tethering function is active or not * @param manager WiFi manager// ww w.j a v a2 s . co m * @return active or not */ private boolean isTethering(final WifiManager manager) { Method method = null; try { method = manager.getClass().getDeclaredMethod("isWifiApEnabled"); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } method.setAccessible(true); try { return (Boolean) method.invoke(manager); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return false; }
From source file:com.codestation.henkakuserver.MainActivity.java
public boolean isConnectedInWifi(boolean wifiOnly) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();/*from w w w .j av a 2s. c o m*/ boolean wifiEnabled = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected() && wifiManager.isWifiEnabled() && networkInfo.getTypeName().equals("WIFI"); if (!wifiOnly && !wifiEnabled) { try { final Method method = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled"); method.setAccessible(true); wifiEnabled = (Boolean) method.invoke(wifiManager); } catch (Exception e) { e.printStackTrace(); } } return wifiEnabled; }
From source file:org.allseen.lsf.sampleapp.view.MainFragment.java
protected boolean isWifiConnected() { NetworkInfo wifiNetworkInfo = ((ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI); // determine if wifi AP mode is on boolean isWifiApEnabled = false; WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); // need reflection because wifi ap is not in the public API try {/*from ww w . ja v a 2 s .c om*/ Method isWifiApEnabledMethod = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled"); isWifiApEnabled = (Boolean) isWifiApEnabledMethod.invoke(wifiManager); } catch (Exception e) { e.printStackTrace(); } //Log.d(SampleAppActivity.TAG, "Connectivity state " + wifiNetworkInfo.getState().name() + " - connected:" + wifiNetworkInfo.isConnected() + " hotspot:" + isWifiApEnabled); return wifiNetworkInfo.isConnected() || isWifiApEnabled; }
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Enable/Disable a Wifi access point", example = "") @APIParam(params = { "boolean, apName" }) public void wifiAP(boolean enabled, String wifiName) { WifiManager wifi = (WifiManager) a.get().getSystemService(a.get().WIFI_SERVICE); Method[] wmMethods = wifi.getClass().getDeclaredMethods(); Log.d(TAG, "enableMobileAP methods " + wmMethods.length); for (Method method : wmMethods) { Log.d(TAG, "enableMobileAP method.getName() " + method.getName()); if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = wifiName;/*from w ww .j a v a 2s . com*/ netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); // try { //MLog.d(TAG, "enableMobileAP try: "); method.invoke(wifi, netConfig, enabled); if (netConfig.wepKeys != null && netConfig.wepKeys.length >= 1) { Log.d(TAG, "enableMobileAP key : " + netConfig.wepKeys[0]); } //MLog.d(TAG, "enableMobileAP enabled: "); mIsWifiAPEnabled = enabled; } catch (Exception e) { //MLog.e(TAG, "enableMobileAP failed: ", e); } } } }