Adb отключить мобильный интернет

Как отключить Wifi через ADB?

Im автоматизация процедуры тестирования для вызова wifi, и мне было интересно, есть ли способ отключить / включить wifi через adb?

Я хотел бы отключить / включить wifi или убить вызов wifi (com.movial.wificall) и перезапустить его.

можно ли это сделать с помощью команд adb и shell?

android.net.wifi.WifiManager setWifiEnabled(true/false) 

Я просто не уверен, как положить его вместе

8 ответов

использование » svc » через ADB (требуется корневой):

adb shell su -c 'svc wifi enable' 
adb shell su -c 'svc wifi disable' 

использование ключевых событий через ADB:

adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 20 & adb shell input keyevent 23 

первая линия запуска » wifi.Wifisettings » активность, которая открывает страницу настроек WiFi. Вторая строка имитирует нажатия клавиш.

Я тестировал эти две строки на Droid X. Но ключевые события выше, вероятно, нужно редактировать в других устройствах из-за разных Настройка макета.

дополнительная информация о» keyevents»здесь.

Я искал то же самое, чтобы включить/выключить bluetooth, и я нашел это:

adb shell svc wifi enable|disable 

простой способ переключения wifi на некорневых устройствах-использовать простое приложение:

public class MainActivity extends Activity < @Override public void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WifiManager wfm = (WifiManager) getSystemService(Context.WIFI_SERVICE); try < wfm.setWifiEnabled(Boolean.parseBoolean(getIntent().getStringExtra("wifi"))); >catch (Exception e) < >System.exit(0); > > 
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi true $ adb shell am start -n org.mytools.config/.MainActivity -e wifi false 
  1. на месте android/android-sdk/platform-tools
  2. shift +щелчок правой кнопкой мыши
  3. откройте cmd здесь и введите следующие команды
    1. adb shell
    2. su
    3. svc wifi enable/disable
    adb shell "svc wifi enable" 

    это сработало и делает действие в фоновом режиме без открытия связанной опции !!

    я протестировал эту команду:adb shell am start-андроид.намерение.действие.MAIN-N com.андроид.настроить./беспроводной доступ в интернет.WifiSettings вклад АБР оболочки keyevent не 19 ввод и АБР оболочки keyevent не 19 & оболочку ADB ввод keyevent не 23

    и работает только на подсказке окна, возможно, из-за какого-то драйвера

    о adb shell svc wifi включить / отключить Я думаю, что только работать с правами root

    settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0 

    иногда, если это делается во время загрузки (т. е. исправить bootloop, такие как это), он не применяется хорошо, и вы можете продолжить также включение режима самолета сначала:

    settings put global airplane_mode_on 1 settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0 

    другой вариант-заставить это с помощью:

    while true; do settings put global wifi_on 0; done 

    протестировано в Android 7 на LG G5 (SE) с (unrooted) stock mod.

    ex: adb shell «svc wifi enable»

    Источник

    How do I disable the Internet connection in Android Emulator?

    I am trying to check Internet connectivity on Android using the following method. I have a Wi-Fi connection.

    private boolean checkInternetConnection() < ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); // Test for connection if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) < return true; >else < // No conection return false; >> 

    I disconnect my PC from the Internet and then try to run the above method. Still it always returns true!? Why?

    try this thing on device not on emulator, it will return always uncertain results on emulator on this things.

    but i have to show the results on the emulator.. Is there any way i can show the results on emulator ?

    Using the Pixel_3a_API_30_x86 and Android 11 in the emulator, this seems pretty much impossible. Wifi turns on again when turned off and airplaine mode makes no difference. What I ended up resorting to was changing URLs or disabling internet connection on my computer.

    11 Answers 11

    From Eclipse

    To disable the Internet connection, go to Eclipse and do

    menu Window -> Show view -> Other -> Android -> Devices 

    Now select your running emulator and again go to:

    menu Window -> Show View -> Other -> Android -> Emulator Control 

    Now in that. set Data to Unregister from Home.

    From Device and Emulator

    On the device or in the emulator, go to:

    Setting -> Wireless & networks -> Airplane Mode -> OK 

    @user370305 yes ofcaurse..that’s from the emulator and device.. okay let me add that too in the answer.

    Ok. I tried all possible options. isAvailable in code returns false . Yet when my service attempts to connect to remote site, it still succeeds and completes the download. Possibly a bug in the emulator?

    For me the From Device and Emulator option also prevented Android Studio studio from being able to connect to the emulator, so wasn’t all that great for debugging!

    Annoyingly, it is still true that setting a Google Android emulator to Airplane mode prevents debuggers running on the PC from connecting to the emulated device! (In my case, Xamarin Studio is the IDE)

    it’s funny: if you turn off wifi on the emulator and you set the emulator’s «data» option to «unregistered» (or Denied) and «signal strength» to «None», the app still gets connectivity! /amazing-internet-magic

    You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn’t have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.

    this doesn’t allow me to debug anymore — eclipse launches a new emulatr after pressing f8 (even after pressing it twice). This is also the case with other methods like airplane off

    WIFI: $ adb shell svc wifi enable $ adb shell svc wifi disable MOBILE DATA: $ adb shell svc data enable $ adb shell svc data disable 

    Turning on and off wifi and mobile data is not the same thing. Sometimes you want to test wifi being on (and maybe connected) but no internet connection.

    Does not work for me in latest version of Android Studio. After executing adb shell svc wifi disable , wifi is still enabled.

    Android Studio 3.0 Update

    Simply drag and open the control center and click on the airplane mode button as what you are doing on your actual device.

    Please bear with me for a very slow emulator.

    I am still getting internet connection, even in airplane mode, because wifi is still enabled and I can’t find any way to disable it

    There are many methods. I am explaining two methods here.

    1. Just hit the F8 key to enable or disable the Internet connection.
    2. Just start your emulator, hold on the power button and then select:

    It will disconnect your emulator from the Internet. If you want to connect again, just hold on the power button again and select:

    And your emulator’s Internet connection will start working!

    even in airplane mode, it can still connect to wifi, so internet is still enabled. also, F8 does nothing for me

    To check on a real device (and also in the emulator), go to:

    Settings > Wireless and Networks > Mobile Networks > Data enabled

    Uncheck it and it will work.

    You can actually disable internet connection in the simulator just as you would in a real phone.

    1. Swipe down the screen to see the notification panel.
    2. Tap on the data network icon
    3. Turn off the cellular network.

    I just tried it successfully in an android 4.4 image loaded into my simulator.

    Recent emulator versions provide an easier way, from an ADT view:

    Window -> Show view -> Other. -> Android -> Emulator Control 

    Simply change «Data» value from «Telephony Status» and test your application again.

    this may have worked back in the days of ADT, but ADT is no longer supported and this doesn’t work for me

    None of the other answers to this question worked for me, the only thing that worked was

    adb shell -> su -> ifconfig wlan0 down

    and you can use ifconfig wlan0 up to bring it back up again. (I had to restart the device, even after executing ifconfig wlan0 up .)

    Obviously make sure mobile data is disabled (or device is in flight mode) before trying this.

    Thanks a lot to noamtm’s answer for the hint!

    Источник

    Adb Commands For Airplane mode and enable disable wifi, bluetooth

    Adb Commands For Airplane mode and enable disable wifi, bluetooth

    Adb Commands For Airplane mode and enable disable wifi, bluetooth

    Adb commands for airplane mode consists of of two commands. One changes the state and another broadcast the intent. Wifi enable and disable is simple which i will explain at the end.

    1. How to turn on airplane mode using adb commands.

    The first command just changes the state of the Airplane mode icon but all radios are still active. Now you need to broadcast the intent right after the setting has been changed to inform the applications that the Airplane mode state has changed. The second line does broadcast the intent. So, you have to run both the commands in sequence.

    adb shell settings put global airplane_mode_on 1
    adb shell am broadcast -a android.intent.action.AIRPLANE_MODE

    2. Turn off airplane mode using adb commands

    adb shell settings put global airplane_mode_on 0
    adb shell am broadcast -a android.intent.action.AIRPLANE_MODE

    3. How to Enable wifi using adb commands

    adb shell svc wifi enable

    4. How to Disable wifi with adb command

    adb shell svc wifi disable

    If you see something like “sh: resetreason: can’t execute: Permission denied” run adb root command before running any commands.

    5. How to turn on Bluetooth ?

    To use these adb commands, you need to have root permission and your android build should be userdebug.

    adb root adb shell service call bluetooth_manager 6

    6. How to turn off Bluetooth

    $adb root
    $adb shell service call bluetooth_manager 6

    If you face any problem in running Adb Commands For Airplane mode, wifi or bluetooth. Please comment below and we will try to resolve.

    You might also like

    How to run iperf, iperf2, iperf3 TCP UDP server and client on DL and UL

    How to copy files using adb commands | adb push | adb pull

    How to copy files using adb commands | adb push | adb pull

    adb commands | adb devices | adb device not found | adb push| adb shell

    adb commands | adb devices | adb device not found | adb push | adb shell

    One thought on “ Adb Commands For Airplane mode and enable disable wifi, bluetooth ”

    How to enable airplane mode in non rooted android device using adb commands without using GUI method like input keyevent or tap x y.
    Android version: 10 command tried:
    settings put global airplane_mode_on 0; am broadcast -a android.intent.action.AIRPLANE_MODE –ez state false issue while using above commands:
    java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=25344, uid=2000
    at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:17980)
    at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:17784)
    at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18702)
    at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:720)
    at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:185)
    at android.os.ShellCommand.exec(ShellCommand.java:104)
    at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:12424)
    at android.os.Binder.shellCommand(Binder.java:916)
    at android.os.Binder.onTransact(Binder.java:790)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:5475)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3426)
    at android.os.Binder.execTransactInternal(Binder.java:1056)
    at android.os.Binder.execTransact(Binder.java:1029)

    Leave a Reply Cancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Источник

    Читайте также:  Домашний интернет мтс заплатить картой
Оцените статью
Adblock
detector