Install Python to run speedtest-cli on android phone with no access to device - via adb


Question

I want to install python on an android phone (the phone is connected to a pi so I don't have any GUI or physical access to the device). I can connect to the phone via adb shell and run/install packages via apk files easily. I want to install python on the device so that I can run speedtest-cli remotely via adb shell. https://github.com/sivel/speedtest-cli
Speedtest-cli requires python. So far I have tried the following based on online articles.
1. Installed termux app via APK. I can access the underlying files remotely. I tried install python using pkg command but could not error below.



1|:/data/data/com.termux/files/usr/bin # ./pkg install python

  
This must NOT be run as root as it will break your environment (root will be required for nearly everything due to changed file permissions)
1|marlin:/data/data/com.termux/files/usr/bin # whoami
root


2. Installed Qpython on the device using adb. However the issue is that when I launch adb command to launch Qpython I see a prompt on the device - Allow Qpython to access media Options - Accept or Deny. Since I don't have access to device I can select either of the options. Is there a way to send command via ADB to select - Accept ?



Would appreciate any other ideas as well. My end goal is to run the speetest-cli utility via adb shell on a device that is not physcially accessible.


Answer

Solved this eventually. Here is what I did -




  1. Installed termux via downloading apk and performing adb install com.termux.apk

  2. Remotely launched the termux app via adb (monkey) (this is needed to complete install on the device) monkey -p com.termux -c android.intent.category.LAUNCHER


  3. once termux is installed I installed python and speedtest-cli on the device using adb input text and keyevents -




    • adb input text "pkg install python"

    • adb input keyevent "66"


    • adb input text "pip install speedtest-cli"



  4. Then navigate to /data/data/com.termux/files/usr/bin
    here you should have the speedtest-cli script that you can invoke from adb shell



    /data/data/com.termux/files/usr/bin # ./speedtest-cli

    Retrieving speedtest.net configuration...
    Testing from XXXXX
    Testing download speed................................................................................
    Download: 20.18 Mbit/s
    Testing upload speed......................................................................................................
    Upload: 3.98 Mbit/s



Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes