Launching default internet browser

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
soutre
Posts: 15
Joined: 18 Aug 2019 07:01

Launching default internet browser

Post by soutre » 12 Oct 2019 11:28

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.

anuraag
Posts: 273
Joined: 24 Jan 2015 02:06

Re: Launching default internet browser

Post by anuraag » 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

soutre
Posts: 15
Joined: 18 Aug 2019 07:01

Re: Launching default internet browser

Post by soutre » 14 Oct 2019 10:59

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...

Post Reply