-1

i try to make a simple webview app for this interactive map: http://gta5online.com/map/interactive > there is also a fullscreen link below the map.

now i created an asset folder and included the "interactive" folder which has all the files, icons, map tiles and html document in it.

i want to load the html document from there into a activity as a webview. so its a local file. i want the app to handle it not the default browser.

here is what i did by now:

i created a new project and added those codes into the activity_home.xml file:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("file:///android_asset/interactive/map.html");
/>

then i added this code to enable internet access in to manifest even if its a local html doc that i want to load (for later uses):

  <uses-permission android:name="android.permission.INTERNET"/>

i also enabled javascript at the first code block as you can see.

should i've put some code into the home.java file too?

in a YT tutorial i saw that he used something like this in the java file:

      #in mainactivity.java
    setContentView(R.layout.activity_main);
    String url ="file:///android_asset/interactive/map.html";
    WebView view=(WebView) this.findViewById(R.id.webView);
    view.getSettings() .setJavaScriptEnabled(true);
    view.loadUrl(url);

can someone please help a noob to achieve this by explaining what i did wrong and simple steps how to complete this app?. i'm sure its simple for you guys even if its that hard for me.

serdox
  • 19
  • 10

3 Answers3

2

Be very careful in Android, you can never place Java code into XML code.

This code:

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();

myWebView.loadUrl("file:///android_asset/interactive/map.html");
webSettings.setJavaScriptEnabled(true);
Jameson
  • 6,400
  • 6
  • 32
  • 53
1

In your activity_home.xml file must be only this:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
walkmn
  • 2,322
  • 22
  • 29
  • and whats with the rest like enable javascript, loading the html file etc? – serdox Nov 02 '15 at 14:53
  • 1
    What is the your problem? Your java code (in your question) put in your MainActivity.java file in onCreate override method. Like this: http://stackoverflow.com/a/3152441/2738172 – walkmn Nov 02 '15 at 15:05
  • hey thanks for answer man. my problem is i'm a beginner. there was some other code inside the java folder as a standard i guess: – serdox Nov 02 '15 at 15:13
  • package comapps.gta5online.gta5interactivemapcheats; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class Home extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); } } – serdox Nov 02 '15 at 15:14
  • should i keep this too? – serdox Nov 02 '15 at 15:14
0

This is due to same origin policy violation, you need to use loaddatawithurl

Read

and

Flexo
  • 87,323
  • 22
  • 191
  • 272
Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17