5

Working on a Go project and using gomobile to generate .apk file. I am trying to open a browser in the go code with a passing URL. I know go supports running CMD commands in different operating systems such as windows and Linux. Wonder to know if there is any code to support Android OS as well. In other words in following code what should I have under

case "android":

func openbrowser(url string) {
    var err error

    switch runtime.GOOS {
    case "linux":
        err = exec.Command("xdg-open", url).Start()
    case "windows":
        err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
    case "darwin":
        err = exec.Command("open", url).Start()
    default:
        err = fmt.Errorf("unsupported platform")
    }
    if err != nil {
        log.Fatal(err)
    }

}
Ashkanxy
  • 2,380
  • 2
  • 6
  • 17

1 Answers1

0

You can try using ADB Shell. Check this question Need command line to start web browser using adb

adb shell am start -a android.intent.action.VIEW -d 'http://stackoverflow.com/?uid=isme\&debug=true'
wakumaku
  • 616
  • 5
  • 5
  • If the command will be executed from the Android device you don't need "adb shell" in the beginning. – dev.bmax Aug 21 '21 at 19:54
  • 1
    Thanks wakumaku and @dev.bmax. I tried both. none of them works. However, i can confirm that without using the "adb shell", there is no error, but the browser is not opened . the "adb shell" is probably needed if i need to open the browser from the Android studio terminal. In other words, exec.Command(" /system/bin/am start -a android.intent.action.VIEW -d http://stackoverflow.com/?uid=isme").Start() does not work. – Ashkanxy Aug 23 '21 at 17:22