How to get access monkey://data/ from native code?

Monkey Forums/Monkey Programming/How to get access monkey://data/ from native code?

nikoniko(Posted 2014) [#1]
Android:

I tried to use monkey protocol to load html page from data folder into webview
_webView.loadUrl("monkey://data/Index.htm");


webview shows 404 error message.

Read internet and change code to use file:// protocol
_webView.loadUrl("file:///android_asset/monkey/Index.htm");


It works but will has some troubles with security.

How to get access to files under data folder in iOS and WP/WinRT targets?


hsutuo(Posted 2014) [#2]
PathToFilePath convert first.


nikoniko(Posted 2014) [#3]
hsutuo wrote:
PathToFilePath convert first.


Hmm, its source

	String PathToFilePath( String path ){
		return "";
	}



Markus(Posted 2014) [#4]
i believe this webview will show extra window.
did you try OpenUrl with local html data?


nikoniko(Posted 2014) [#5]
Markus wrote:
i believe this webview will show extra window.


I create webview in the current layout, it doesn't open new window when webviewclient released.


Markus wrote:
did you try OpenUrl with local html data?


I didn't. Do you mean that I can to view java code for this call?


nikoniko(Posted 2014) [#6]
nikoniko wrote:
I didn't. Do you mean that I can to view java code for this call?


App crashes on OpenUrl("monkey://data/Index.htm") line and OpenUrl("file:///adroid_asset/monkey/Index.htm") too.


Ironstorm(Posted 2014) [#7]
-- PathToFilePath convert first.
Hmm, its source


This one is the native PathToFilePath method.

String PathToFilePath( String path ){
		if( !path.startsWith( "monkey://" ) ){
			return path;
		}else if( path.startsWith( "monkey://internal/" ) ){
			File f=_activity.getFilesDir();
			if( f!=null ) return f+"/"+path.substring(18);
		}else if( path.startsWith( "monkey://external/" ) ){
			File f=Environment.getExternalStorageDirectory();
			if( f!=null ) return f+"/"+path.substring(18);
		}
		return "";
	}


You'll find it in "MonkeyXPro-Versionnumber-/targets/android/modules/native/androidgame.java"
Same goes for iOS and other.

OpenURL() doesn't call PathToFilePath. So monkey://data will result in an error. Because monkey://data/whatever isn't a valid file path in java.
This native java code should work. Haven't tested it.

File f=BBAndroidGame.AndroidGame().GetActivity().getFilesDir();
if( f!=null ) f+"/Index.htm"; // Index.htm should be inside your data folder
_webView.loadUrl(f);



nikoniko(Posted 2014) [#8]
Ironstorm

Thanks!