0

i have a interactive map folder. i try to create a webview app with local files.

inside the folder are all the files needed to load the map. gta5online.com/map-interactive

also included is a html file that i tried to open in an app. i just pasted the folder inside the main application folder for android studio.

i tried to put the path in the code as you can see for the string. when i run emulator it says it cannot find the file. what do i need to put there. can someone give me the exact one please? i'm a noob.

the path on my pc is: C:\Users\me\AndroidStudioProjects\MyApplication\interactive\map.html

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String url ="file:/interactive/map.html";
    WebView view=(WebView) this.findViewById(R.id.webView);
    view.getSettings() .setJavaScriptEnabled(true);
    view.loadUrl(url);
serdox
  • 19
  • 10

1 Answers1

0

The best way to reference html content in this case is to put it in an ./assets folder and use the URI file:///android_asset/ to refer to it.

See for example the reply here: How to get URI from an asset File?

To be fair, I haven't tried that since Android Studio became a thing and gradle changed the default project layout -- hopefully that doesn't further complicate matters for you.

Jameson
  • 6,400
  • 6
  • 32
  • 53
  • but the html file is in that particular map folder called interactive. i didn't code it. when i would take it out and put somewhere else i guess it would break and wouldn't load the files for the map that are in the same folder. can i just use it inside that folder without moving? – serdox Nov 01 '15 at 08:39
  • Yea. Move your entire HTML structure so that the document tree is `./assets`. `./assets/foo/bar/some_file.baz` -- whatever. Then the URI is `file:///android_asset/foo/bar/some_file.baz`. – Jameson Nov 01 '15 at 08:41
  • i guess i cant take the html file out of the original map folder. it seems like to be coded so that it needs to reside inside the same folder with the map tiles, icons, folders, etc. i couldn't change the code inside the documents. is it possible to do it while keeping it inside the folder – serdox Nov 01 '15 at 08:46
  • Dude, move the whole folder. – Jameson Nov 01 '15 at 08:47
  • oh ok. sorry im really bad at this. where is this folder located assets etc. – serdox Nov 01 '15 at 08:51
  • No worries, the assets folder is a bag of tricks anyhow. It looks like with Android Studio, the location is ./src/main/assets : https://stackoverflow.com/questions/18302603/where-to-place-assets-folder-in-android-studio – Jameson Nov 01 '15 at 08:53
  • okey the path is now C:\Users\Serdar\AndroidStudioProjects\MyApplication\app\src\main\assets\interactive\map.html right? – serdox Nov 01 '15 at 08:58
  • That looks right. So your URI is `file:///android_asset/interact‌​ive/map.html` – Jameson Nov 01 '15 at 09:00
  • but the map does not resemble correctly. i guess it needs different adapting then the on gta5online.com/map-interactive. dammit. i really hoped it would work. – serdox Nov 01 '15 at 09:13
  • hey jameson i tried some instructions and created a new question. can you take a look at whats wrong there: http://stackoverflow.com/questions/33480171/errors-for-simple-webview-app-in-android-studio – serdox Nov 02 '15 at 14:45