Libathos
Libathos

Reputation: 3362

Is the browser used in Android and iOS so different?

I'm developing an android application and a colleague of mine is developing the same application for iOS. In this application is needed to load a 360 panorama which is located on internet. In the iOS application, a HTML5 string is used to wrap the URL of the panorama and the WebView loads it normally when I used the same String in an Android WebView, the url won't open. So my question is are the webiews between these two OS so different? should I enable some settings of my webview? I'll post you the code and the string just in case you can make something out of it.Thank you in advance

    webView2.getSettings().setJavaScriptEnabled(true);
    webView2.getSettings().setDomStorageEnabled(true);
String target = "<html>
                 <head> 
                 <style type=\"text/css\">
                 iframe {position:absolute; }
                 body {background-color:#000; margin:0;} 
                </style> 
                </head>  
                <body>
                <iframe width=\"100%%\" height=\"100%%\" 
                src=\"%http://360photo.gr/panorama/ipad/antalki/antalki_2.html\" frameborder=\"0\" allowfullscreen></iframe>        </body>        </html>" ;

I might be messing the String somewhere and haven't noticed this is the String that works in iOS

    NSString *videoHTML = [NSString stringWithFormat:@"\
                       <html>\
                       <head>\
                       <style type=\"text/css\">\
                       iframe {position:absolute; }\
                       body {background-color:#000; margin:0;}\
                       </style>\
                       </head>\
                       <body>\
                       <iframe width=\"100%%\" height=\"100%%\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
                       </body>\
                       </html>", self.urlToPlay];

And this is how I load the Data:

webView2.loadData(target, "text/html", null);

Upvotes: 0

Views: 465

Answers (3)

Matt Gaunt
Matt Gaunt

Reputation: 9821

Have you added the internet permission to your Android Manifest?

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

EDIT

Had a crack at adding some more solid CSS to your page and got it working on an example app.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

<title>Demo</title>

<style>
  html, body {
    padding: 0;
    margin: 0;
  }

  html {
    min-width: 100%;
    min-height: 100%;
  }

  body {
    width: 100%;
    height: 100%;
    background-color: red;
  }
</style>

</head>
<body>
  <iframe width="100%" height="100%"
               src="http://360photo.gr/panorama/ipad/antalki/antalki_2.html" frameborder="0" allowfullscreen>
          </iframe>
</body>
</html>

Upvotes: 0

Apurv
Apurv

Reputation: 17186

There is an extra "%" sign in the URL which you have prepared for Android. Just remove it from the value of "src" and it should get open for Android browser as well.

I simply put below code in sample.html file and loaded into webview. It worked well and loaded the image perfectly. It seems problems are with escape characters and extra "%" sign in width and height attributes of iframe.

<html>
     <head>
          <style type="text/css">
          iframe {position:absolute; }
          body {background-color:#000; margin:0;}
          </style>
     </head>

     <body>
          <iframe width="100%" height="100%"
               src="http://360photo.gr/panorama/ipad/antalki/antalki_2.html" frameborder="0" allowfullscreen>
          </iframe>
     </body>
</html>

Upvotes: 1

Libathos
Libathos

Reputation: 3362

So according to this link I can't do what I've set out to do, at least not for KitKat, is that correct or did I misread something?

Upvotes: 0

Related Questions