Open a URL??

Monkey Forums/Monkey Programming/Open a URL??

GfK(Posted 2012) [#1]
The documented "Execute" function seems to offer what I want, but the compiler does not seem to recognise it.

Is there any way to open a specific page of a website (like BlitzMax's OpenURL())?


Xaron(Posted 2012) [#2]
Here it is:

Monkey code:
#If TARGET <> "android" And TARGET <> "ios" And TARGET <> "xna"
#Error "MUtils is not currently available for target '${TARGET}'."
#End

Import "native/mutils.${TARGET}.${LANG}"

Extern

#If LANG="cpp"
  Function LaunchNativeBrowser:Void( address:String, windowsName:String ) = "MUtils::launchBrowser"
#Else
  Function LaunchNativeBrowser:Void( address:String, windowsName:String ) = "MUtils.launchBrowser"
#End

Public

Function LaunchBrowser( address:String, openNewWindow:Bool = True )
	Local windowName:String = "_self"
	If( openNewWindow )
		windowName = "_blank"
	End If
	LaunchNativeBrowser( address, windowName )
End Function


Native code for Android:

import android.content.Context;
import android.location.LocationManager;
import android.location.LocationListener;
import android.location.Location;
import android.app.Activity;
import android.app.AlertDialog;
import android.widget.EditText;
import android.content.DialogInterface;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.LinearLayout;


class MUtils
{
	static void launchBrowser(String address, String windowName) {
		android.net.Uri uriUrl = android.net.Uri.parse(address);
		android.content.Intent launchBrowserActivity = new android.content.Intent(android.content.Intent.ACTION_VIEW, uriUrl);
		MonkeyGame.activity.startActivity(launchBrowserActivity);
	}
};


Native Code for iOS:
class MUtils
{
public:
	static void launchBrowser(String address, String windowName)
	{
		NSString *NSstrURL = address.ToNSString();
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSstrURL]];
	}
};


Native Code for Windows Phone 7:
class MUtils
{
  public static void launchBrowser( String address, String windowName )
  {
    MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();

    marketplaceDetailTask.ContentIdentifier = address;
    marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;

    marketplaceDetailTask.Show();
  }
};



GfK(Posted 2012) [#3]
Thanks - I've actually just discovered that Diddy has a LaunchBrowser function, which probably does the above.

:)


MikeHart(Posted 2012) [#4]
Execute is part of the OS module which is only available for "StdCpp" and "Glfw".


therevills(Posted 2012) [#5]
Diddy has a LaunchBrowser function, which probably does the above.

It does ;)

Also the new version of Monkey 67 has the OpenURL command, although you can not open it to a new window if you are using it in HTML like the Diddy version.


GfK(Posted 2012) [#6]
Oh, right. I think i'll stick with v66 for now until there's a non-experimental update.


therevills(Posted 2012) [#7]
Wise choice to stick with v66 for now... just remember to add the Android 4.2 fix if you are planning an Android release ;)