0

using qpython (python2.x), from what i can see, the way to open a web browser on android from a python script is by first getting the "application uri?" by calling

  from androidhelper import Android
  droid = Android()
  droid.getLaunchableApplications()

where i got "com.google.android.apps.chrome.Main" as my "application uri?" next, i use droid.startActivity() to launch the application. the syntax is as follows.

  startActivity(
      String action,
      String uri[optional],
      String type[optional]: MIME type/subtype of the URI,
      JSONObject extras[optional]: a Map of extras to add to the Intent,
      Boolean wait[optional]: block until the user exits the started activity,
      String packagename[optional]: name of package. If used, requires classname to be useful,
      String classname[optional]: name of class. If used, requires packagename to be useful)

a working use of this code that i googled is below. it opens up the youtube application and goes to a specific video.

  droid.startActivity('android.intent.action.VIEW', 
      'vnd.youtube:3nH_T9fLd_Q', None, None, False, None, None)

but i cant quite figure out how to turn this code into the code i need. i want to open the file "new.html" (located in the current working directory) and display it in the chrome browser.

1 Answers1

0

sl4a documentation

I tried lots of different ways to do what you want to do:

The best way: intent with category

Make an intent with CATEGORY_BROWSABLE. This should launch an app to browse the HTML; if there are multiple apps, it'll ask the user which to launch.

from androidhelper import Android
droid = Android()
uri2open = "file:///sdcard/qpython/scripts/test.html"
intent2start = droid.makeIntent("android.intent.action.VIEW", uri2open, "text/html", None, [u"android.intent.category.BROWSABLE"], None, None, None)
print(droid.startActivityForResultIntent(intent2start.result))

System browser

Launch the built-in Android system browser.

droid.startActivity("android.intent.action.VIEW", uri2open, "text/html", None, False, "com.android.browser", "com.android.browser.BrowserActivity")

HTML viewer

Just view, giving no package name and class name. Usually Android will launch the HTML viewer.

droid.startActivity("android.intent.action.VIEW", uri2open, "text/html", None, False, None, None)

Sl4a webViewShow

Use sl4a's webViewShow directly.

droid.webViewShow(uri2open)

If you like this answer, remember to upvote or set mine as the answer! Hope this help you!

Kirk
  • 446
  • 4
  • 18