2016-03-31 9 views
0

Ich versuche, den untenstehenden HTML-Code mit JS-Skripten in Webview zu laufen.Wie html mit JS-Skripten auf WebView laufen lassen

<html> 
    <script type="text/javascript" src="//static.apester.com/js/sdk/v1.1/apester-sdk.min.js"></script> 
    <body> 
     <interaction id="56fda67582287b5830c4ec8f"></interaction> 
    </body> 
</html> 

Der obige Code läuft auf Tryit Editor

ich die INTERNET Erlaubnis zum Manifest

XML-Code (nicht neu) hinzugefügt haben:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="bet.abpla.webviewdemo02.MainActivity"> 

    <WebView 
     android:id="@+id/webview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 

Java-Code:

public class MainActivity extends AppCompatActivity { 

    String Identifier = "56fda67582287b5830c4ec8f"; 
    String Mime = "text/html"; 
    String Encoding = "UTF-8"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     WebView webView = (WebView) findViewById(R.id.webview); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.loadDataWithBaseURL(null, getHTMLData(Identifier), Mime, Encoding, null); 
    } 

    private String getHTMLData(String ApesterId) { 

     return "<!DOCTYPE html>" + 
       "<html>" + 
       "<script type=\"text/javascript\" src=\"//static.apester.com/js/sdk/v1.1/apester-sdk.min.js\"></script>" + 
       "<body>" + 
       "<interaction id=\"" + ApesterId + "\"></interaction>" + 
       "</body>" + 
       "</html>"; 
    } 

} 

den obigen HTML-Code einfügen auf Tryit Editor wird das gewünschte Ergebnis angezeigt werden soll.

Leider in Android, zeigt es nichts (einfach ein leerer weißer Bildschirm mit der Standardaktionsleiste ohne den Hello World-Text). Kann mir jemand sagen, wo ich falsch gelaufen bin?

Grüße

Antwort

0

Änderung die letzte Zeile des Codes:

webview.loadDataWithBaseURL("", getHTMLData(Identifier), "text/html", "UTF-8", ""); 
Verwandte Themen