Я пытаюсь html файл показать внутри WebView в android, но при попытке увидеть черный экран на моем android телефоне, Html имеет iframe
Html код
<iframe style="width:100%; height:100%;" id="webPage" frameborder="0" src="http://www.youtube.com/embed/XGSy3_Czz8k">
</iframe>
<script>
var Url, Interval;
function init() {
document.getElementById('webPage').setAttribute('src', Url);
}
function setParams(params) {
//console.log(params);
params.forEach(element => {
switch (element.key) {
case "Url":
Url = element.value;
break;
case "Interval":
Interval = element.value;
break;
}
});
document.getElementById('webPage').setAttribute('src', Url);
setInterval(function () {
document.getElementById('webPage').setAttribute('src', Url);
}, (Interval * 60 * 1000));
}
function listener(event) {
setParams(event.data);
}
if (window.addEventListener) {
window.addEventListener('message', listener, false);
} else if (window.attachEvent) { // ie8
window.attachEvent('onmessage', listener);
}
function deleteContent()
{try {var el = document.getElementById ('webPage'); el.setAttribute ( 'ср c, "о: пустой"); el.parentNode.removeChild (эл); } catch (err) {console.log ("ОШИБКА удаления веб-страницы:" + err); }}
Android Код
browser.setInitialScale(60);
//WebView browser = new WebView(context);
browser.getSettings().setJavaScriptEnabled(true);
browser.loadUrl( "file:///android_asset/index.html");
browser.setWebChromeClient(new WebChromeClientCustomPoster());
//((Activity) context).setContentView(browser);
WebSettings ws = browser.getSettings();
ws.setAllowFileAccess(true);
ws.setAllowFileAccessFromFileURLs(true);
ws.setAllowUniversalAccessFromFileURLs(true);
ws.setJavaScriptEnabled(true);
ws.setJavaScriptCanOpenWindowsAutomatically(true);
ws.setAllowContentAccess(true);
ws.setDomStorageEnabled(true);
browser.setWebViewClient(new WebViewClient(){
@SuppressLint("SyntheticAccessor")
public void onPageFinished(WebView view, String url){
// do your stuff here
JSONObject userData = new JSONObject();
try {
userData.put("PlayerCode", CommonUseFunc.getJsonText("Player","PlayerCode"));
userData.put("PrivateKey",CommonUseFunc.getJsonText("Player","PrivateKey"));
userData.put("PublicKey",CommonUseFunc.getJsonText("Player","PublicKey"));
userData.put("Api",CommonUseFunc.getJsonText("General","ApplicationServer","API"));
userData.put("VideoMode","0");
userData.put("BasePath", Objects.requireNonNull(context.getExternalFilesDir(null)).getAbsolutePath());
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject jsonObjectInit = new JSONObject();
try{
jsonObjectInit.put("MessageType","init");
jsonObjectInit.put("Data",userData);
browser.evaluateJavascript("javascript:PIXAGE.Platform.WebMethod.receiveMessage('" + jsonObjectInit + "')",
null);
Utils.logProcess(Utils.timeInfo(), "StartManager", "initialize Web View", 0);
}catch (JSONException e){
e.printStackTrace();
Utils.logProcess(Utils.timeInfo(), "StartManager", "initialize Web View Eror", 1);
}
JSONObject jsonObject = new JSONObject();
JSONObject obj = null;
try {
obj = new JSONObject(getPublishment);
} catch (JSONException e) {
e.printStackTrace();
}
try {
jsonObject.put("Guid",1111);
jsonObject.put("MessageType","newPublishment");
jsonObject.put("Data",obj);
browser.evaluateJavascript("javascript:PIXAGE.Platform.WebMethod.receiveMessage('" + jsonObject + "')",
null);
Utils.logProcess(Utils.timeInfo(), "StartManager", "Data Sended", 0);
} catch (JSONException e) {
e.printStackTrace();
Utils.logProcess(Utils.timeInfo(), "StartManager", "Data Sended Eror", 0);
}
}
});