简体   繁体   中英

Why iframe works in webview on Android 4.0+ ICS?

I load a Google Docs' iframe into a webview in Android, this iframe is loading a PPT file (Power Point file) from a external server of Google Docs. This is the Android Code:

public class Test_iframeActivity extends Activity {

private WebView webView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    webView = (WebView) findViewById(R.id.wv);
    webView.getSettings().setJavaScriptEnabled(true);

    //String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
    String customHtml = "<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true' width='100%' height='100%' style='border: none;'></iframe>";
    webView.loadData(customHtml, "text/html", "UTF-8");
}}

My question is... why I can see the iframe works fine into Android 4.0 but I can't see it into Android 2.1 to 2.3? (I don't know if in Android 3 works).

SOLVED!

The mistake was the ASCII encoding... I shoud replace the #, %, /, and ? by other characters, please check http://developer.android.com/reference/android/webkit/WebView.html#loadData(java.lang.String , java.lang.String, java.lang.String) for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM