Android How to enable a hot spot in Android programmatically

As long as I know, the API for the AP Enable method is missing, but I can use reflection to set it. That's what I'm doing

wifi_manager = (WifiManager) this.getSystemService(HotSpot_TrisActivity.this.WIFI_SERVICE); btnEnableAP = (Button)findViewById(R.id.btnEnableAP); btnEnableAP.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub WifiConfiguration wifi_configuration = null; wifi_manager.setWifiEnabled(false); try { //USE REFLECTION TO GET METHOD "SetWifiAPEnabled" Method method=wifi_manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method.invoke(wifi_manager, wifi_configuration, true); } 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(); } } }); 
+20
java android
Dec 19 '12 at 6:19 06:19
source share

No one has answered this question yet.

See similar questions:

53
Android enables and disables Wi-Fi HotSpot programmatically
7
Start / stop built-in Wi-Fi / USB modem from code?

or similar:

3799
How do I read / convert an InputStream to a string in Java?
3606
Close / hide Android soft keyboard
3324
How to generate random integers in a specific range in Java?
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2284
How can I fix the 'android.os.NetworkOnMainThreadException'?
2097
Is there a way to run Python on Android?
1844
What is "Context" on Android?



All Articles