Page 1 of 1

Launching default internet browser

Posted: 12 Oct 2019 11:28
by soutre
Hello I'm giving a flow a try that would open an html file. However, Automagic's selection for the file recognizes it as a text file. Is there a way to pull the default web browser as a variable? This variable would be passed to the action "Open URL in browser."

I have tried:

Executing shell command to use internal webview browser. This results in permissions error.

Searching through global, local, and system init variables.

Entering "html://" for the file location prefix.

Thank you for any insight and your time.

Re: Launching default internet browser

Posted: 13 Oct 2019 04:36
by anuraag

Code: Select all

browserIntent = callJavaConstructor("android.content.Intent", "Intent(java.lang.String, android.net.Uri)", "android.intent.action.VIEW", callJavaStaticMethod("android.net.Uri", "parse(java.lang.String)", "http://"));
resolveInfo = callJavaMethod(callJavaMethod(getContext(), "android.content.Context", "getPackageManager()"), "android.content.pm.PackageManager", "resolveActivity(android.content.Intent, int)", browserIntent, getJavaStaticField("android.content.pm.PackageManager", "MATCH_DEFAULT_ONLY"));
packageName = getJavaField(getJavaField(resolveInfo, "android.content.pm.ResolveInfo", "activityInfo"), "android.content.pm.ActivityInfo", "packageName");
packageName will contain your required variable

Re: Launching default internet browser

Posted: 14 Oct 2019 10:59
by soutre
anuraag wrote:
13 Oct 2019 04:36

Code: Select all

browserIntent = callJavaConstructor("android.content.Intent", "Intent(java.lang.String, android.net.Uri)", "android.intent.action.VIEW", callJavaStaticMethod("android.net.Uri", "parse(java.lang.String)", "http://"));
resolveInfo = callJavaMethod(callJavaMethod(getContext(), "android.content.Context", "getPackageManager()"), "android.content.pm.PackageManager", "resolveActivity(android.content.Intent, int)", browserIntent, getJavaStaticField("android.content.pm.PackageManager", "MATCH_DEFAULT_ONLY"));
packageName = getJavaField(getJavaField(resolveInfo, "android.content.pm.ResolveInfo", "activityInfo"), "android.content.pm.ActivityInfo", "packageName");
packageName will contain your required variable
This seems to work well, thank you for the great solution. However, with "View Web URL Intent Received" the default browser happens to be Automagic. When trying to send a link to a file, Automagic will not parse it using the web browser. Instead it throws an error. It seems the "Open URL in browser" is a little misleading because it doesn't actually attempt to open all paths in the browser if it so happens to be a file. It seems to first check with the system which app is most suitable. With advances in web browsers this action should attempt to open everything including files in the default web browser. This may be a bug with Automagic but not for certain?

Thank you once again...