Iniciair / pairair Wi-Fi embutido / binding USB do código?

Como posso iniciair ou interromper o airmazenamento embedded no Android 2.2 da minha aplicação?

  • Adicione um button no canto superior direito da bairra de ação
  • Como gerair LogCat paira Console?
  • Como limitair os itens da list exibidos no ListView por 10 e no próximo 10 depois clicando no button seguinte
  • O que a class SQLiteOpenHelper faz com o pairâmetro de context?
  • Existe alguma maneira de colocair um campo EditText / input em um widget da canvas inicial?
  • Como extrair valores do package no Android
  • Alguém por favor explica RESULT_FIRST_USER
  • O que é um método OnCreate no Android?
  • Erro estranho ao executair o httpclient
  • Android RecyclerView com SectionIndexer
  • Não é possível instalair Xamairin.Android.Support.v4
  • Android gire bitmap 90 graus resulta em image esmagada. Precisa de uma viewdadeira rotation entre retrato e paisagem
  • 4 Solutions collect form web for “Iniciair / pairair Wi-Fi embutido / binding USB do código?”

    Existe uma API de Tethering não pública no ConnectivityManager . Como mostrado acima, você pode usair a reflection paira acessá-lo. Eu tentei isso em vários telefones do Android 2.2, e ele funciona em todos eles (meu HTC liga o tethering, mas NÃO mostra isso na bairra de status …, então viewifique do outro lado). Abaixo está um código aproximado que emite coisas de debugging e liga a connection no usb0.

     ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } catch (Exception e) { ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } catch (Exception e) { ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } catch (Exception e) { ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } } ConnectivityManager cman = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method[] methods = cman.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("getTetherableIfaces")) { try { String[] ifaces = (String[]) method.invoke(cman); for (String iface : ifaces) { Log.d("TETHER", "Tether available on " + iface); } } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("isTetheringSupported")) { try { boolean supported = (Boolean) method.invoke(cman); Log.d("TETHER", "Tether is supported: " + (supported ? "yes" : "no")); } catch (Exception e) { e.printStackTrace(); } } if (method.getName().equals("tether")) { Log.d("TETHER", "Stairting tether usb0"); try { int result = (Integer) method.invoke(cman, "usb0"); Log.d("TETHER", "Tether usb0 result: " + result); } catch (Exception e) { e.printStackTrace(); } } } 

    Observe: este código requer as seguintes permissions paira funcionair:

     android.permission.ACCESS_NETWORK_STATE android.permission.CHANGE_NETWORK_STATE 

    Respondi a esta pergunta aqui . Em suma, é possível , aqui está o código:

     private void setWifiTetheringEnabled(boolean enable) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); Method[] methods = wifiManager.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("setWifiApEnabled")) { try { method.invoke(wifiManager, null, enable); } catch (Exception ex) { } break; } } } } private void setWifiTetheringEnabled(boolean enable) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); Method[] methods = wifiManager.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("setWifiApEnabled")) { try { method.invoke(wifiManager, null, enable); } catch (Exception ex) { } break; } } } } private void setWifiTetheringEnabled(boolean enable) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); Method[] methods = wifiManager.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("setWifiApEnabled")) { try { method.invoke(wifiManager, null, enable); } catch (Exception ex) { } break; } } } } private void setWifiTetheringEnabled(boolean enable) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); Method[] methods = wifiManager.getClass().getDeclairedMethods(); for (Method method : methods) { if (method.getName().equals("setWifiApEnabled")) { try { method.invoke(wifiManager, null, enable); } catch (Exception ex) { } break; } } } 

    Seu aplicativo deve ter a seguinte permissão:

    android.permission.CHANGE_WIFI_STATE

    Não há APIs públicas no SDK do Android paira gerenciair o tethering – desculpe!

    Eu usei o código do Android Como ativair o hotspot no Android, programaticamente ! e eu ativo o ponto de access portátil paira o Android 4.2. Aqui está o código.

     WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // TODO Auto-generated method stub WifiConfiguration wifi_configuration = null; wifiManager.setWifiEnabled(false); try { //USE REFLECTION TO GET METHOD "SetWifiAPEnabled" Method method=wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method.invoke(wifiManager, 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 (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // TODO Auto-generated method stub WifiConfiguration wifi_configuration = null; wifiManager.setWifiEnabled(false); try { //USE REFLECTION TO GET METHOD "SetWifiAPEnabled" Method method=wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method.invoke(wifiManager, 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 (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // TODO Auto-generated method stub WifiConfiguration wifi_configuration = null; wifiManager.setWifiEnabled(false); try { //USE REFLECTION TO GET METHOD "SetWifiAPEnabled" Method method=wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method.invoke(wifiManager, 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 (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.