Launching a Web Browser on Android Using ADB Commands

Launching a Web Browser on Android Using ADB Commands

22 April 2024 Stephan Petzl Leave a comment Tech-Help

Developers often need to launch applications or carry out specific actions on their Android devices directly from their development machines. One powerful tool at their disposal is the Android Debug Bridge (ADB), which allows for a wide range of interactions with the device. In this article, we’ll guide you through the process of launching a web browser on an Android device using ADB commands to open a specific webpage.

Basic ADB Command to Open a Web Page

To open a web page using the default browser on the Android device, you can issue the following ADB command:

adb shell am start -a android.intent.action.VIEW -d http://www.example.com

This command utilizes the am (Activity Manager) tool to create an intent that triggers the action VIEW and opens the provided URL in the device’s default web browser.

Handling URLs with Special Characters

If your URL contains symbols or characters that might be interpreted by the shell, it’s important to enclose the URL in quotes to prevent misinterpretation:

adb shell am start -a android.intent.action.VIEW -d 'http://www.example.com/?uid=isme&debug=true'

Quoting the URL ensures that the command is executed correctly without any alterations to the URL structure.

Opening a Specific Browser

If you need to open a URL in Google Chrome rather than the default browser, you can specify the browser’s package and activity name:

adb shell am start \
-n com.android.chrome/com.google.android.apps.chrome.Main \
-a android.intent.action.VIEW -d 'file:///sdcard/example.html'

Additionally, if you need to grant Chrome permission to read from the device’s external storage, you can use:

adb shell pm grant com.android.chrome android.permission.READ_EXTERNAL_STORAGE

Note that if you’re using Chrome Canary, replace com.android.chrome with com.chrome.canary in the commands above.

Alternative Methods

For devices where the above methods may not apply, such as a Kindle device, you might need to use a different command to start the browser:

adb shell am start -n com.amazon.cloud9/.browsing.BrowserActivity

This command directly invokes the activity responsible for the browser on a Kindle device.

Automating Browser Launch with Repeato

While ADB commands provide a manual way to launch browsers and perform tasks, automating these actions can save time and increase efficiency. This is where Repeato, a No-code test automation tool for iOS and Android, comes into play.

Repeato can help you automate the process of launching web browsers and performing subsequent actions within them. It’s fast to edit and run tests, utilizing computer vision and AI to interact with the app as a user would. Repeato works with various app frameworks, including react-native, flutter, and unity, and includes ADB on board, allowing for the execution of ADB commands via script steps.

By using Repeato, you can integrate the launching of web browsers into your automated testing routines, ensuring that your app’s web interactions function correctly across updates and changes.

Conclusion

Launching a web browser on an Android device using ADB is a simple yet powerful technique that can be a part of a developer’s toolkit. Remember to handle URLs with care to avoid shell interpretation issues and to specify the correct browser if necessary. For those looking to streamline their testing process and integrate automated solutions, Repeato provides a seamless way to incorporate these actions into your testing workflow.

For more insights on ADB commands and their application in development and testing, explore our articles on managing ADB shell with multiple connected devices and launching Android applications via ADB.

Like this article? there’s more where that came from!