Android webview not loading the js but works in chrome browser - android-webview

I wanted to display a script which has ads in it. It works fine when we load in chrome browser and emulate in a device. But to doesn't work in Android
This the script:
<div id="ym_12345" class="ym"></div><script type="text/javascript">(function(e,t){if(t._ym===void 0){t._ym="";var m=e.createElement("script");m.type="text/javascript",m.async=!0,m.src="//static.yieldmo.com/ym.min.js",(e.getElementsByTagName("head")[0]||e.getElementsByTagName("body")[0]).appendChild(m)}else t._ym instanceof String||void 0===t._ym.chkPls||t._ym.chkPls()})(document,window);</script>
I have a web view layout:
Code:
String html =
"<div id=\"ym_12345\" class=\"ym\"></div>" +
"<script type=\"text/javascript\">(function(e,t){if(t._ym===void 0){t._ym=\"\";var m=e.createElement(\"script\");" +
"m.type=\"text/javascript\",m.async=!0,m.src=\"//static.yieldmo.com/ym.min.js\",(e.getElementsByTagName(\"head\")[0]" +
"||e.getElementsByTagName(\"body\")[0]).appendChild(m)}else t._ym instanceof String||void 0===t._ym.chkPls||t._ym.chkPls()})" +
"(document,window);</script>";
wv=(WebView)findViewById(R.id.webview_ndn);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(PluginState.ON);
//wv.getSettings().setAllowContentAccess(true);
wv.getSettings().setSupportMultipleWindows(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setDomStorageEnabled(true);
wv.setWebChromeClient(new WebChromeClient());
//wv.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
wv.loadData(html, "text/html", "UTF-8");

Related

Open android browser in InAppBrowser

Using the following code opens InAppBrowser. I would like to open the other browsers like Chrome and anything that comes with Android.
var data = '<form id="Form" action="http://www.example.com/api/form/" method="post">' +
'<input type="hidden" name="firstname" value="' + firstname + '">' +
'<input type="hidden" name="lastname" value="' + lastname + '">' +
'</form><script type="text/javascript">document.getElementById("Form").submit();</script>';
var pageContentUrl = 'data:text/html;base64,' + btoa( pageContent );
let browser = new InAppBrowser(data, '_blank', 'hidden=no,location=no,clearsessioncache=yes,clearcache=yes');
var ref = cordova.InAppBrowser.open(url, target, options);
target: The target in which to load the URL, an optional parameter that defaults to _self. (String)
_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.
So therefore, your code with _system should do what you want
let browser = new InAppBrowser(data, '_system', 'hidden=no,location=no,clearsessioncache=yes,clearcache=yes');
You should read the documentation

How to stream video to browser with Kodi

Not sure if this is the correct place to ask this but here goes nothing.
I setup openelec's Kodi on a Raspberry pi2. I uploaded a video and managed to get it to play on a connected TV via HDMI. What I can't seem to figure out is how to have Kodi serve as a media server so I can browse media using my phone's or computer's browser and play it. I've been through the settings available, installed several addons(i.e chorus etc) and I still can't see how to make this happen. Whenever I open a video on my browser after logging into the Kodi web interface, it still plays it on the TV connected to the PI.
Almost all Google results out there talk about casting from device onto TV and chromecast. I want to be able to play this media on my local browser. And no, I can't use the Kodi app because I'm using an un-supported Phone and computer OS.
In your case, it's better to use plex instead of kodi.
Kodi is not exactly a media server, it works as a media center. However, with plex, you can set up your media center and have access to your media from your web browser.
Try looking for the differences between kodi and plex.
Chorus should still have an option to play the video in the browser. It seems to not work with Chrome or Firefox anymore, but have a look here: https://github.com/xbmc/chorus2/issues/127
This functionality depends on Flash Player, this feature had been removed from most of the web-browsers.
REF: https://support.google.com/chrome/answer/6258784?visit_id=637521928282450874-904852602&rd=1
I've modified the Chorus web interface to allow streaming with a nodejs process in the background.
NodeJS script:
const express = require('express')
const fs = require('fs')
const path = require('path')
const app = express()
const url = require('url')
const gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(fs)
app.get('/video', function(req, res) {
var q = url.parse(req.url, true).query;
var filepath = q.src;
fs.stat(filepath, function(err, stats){
if (err){
if (err.code === 'ENOENT'){
//404 Error if file not found
res.writeHead(404, {
"Accept-Ranges" : "bytes",
"Content-Range" : "bytes " + start + "-" + end + "/" + total,
"Content-Length" : chunksize,
"Content-Type" : "video/mp4"
});
}
res.end(err);
}
var start;
var end;
var chunksize;
var total = stats.size;
var range = req.headers.range;
if (range) {
var parts = range.replace(/bytes=/, "").split("-");
start = parseInt(parts[0], 10);
end = parts[1] ? parseInt(parts[1], 10) : total - 1;
} else {
start = 0;
end = total - 1;
}
if (start > end || start < 0 || end > total - 1){
//error 416 is "Range Not Satisfiable"
res.writeHead(416, {
"Accept-Ranges" : "bytes",
"Content-Range" : "*/" + stats.size,
"Content-Type" : "video/mp4"
});
res.end();
return;
}
if (start == 0 && end == (total -1)){
res.writeHead(200, {
'Accept-Ranges': 'bytes',
'Content-Range': `bytes ${start}-${end}/${total}`,
'Content-Length': total,
'Content-Type': 'video/mp4'
});
} else {
chunksize = (end - start) + 1;
res.writeHead(206, {
'Content-Range': `bytes ${start}-${end}/${total}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4'
});
}
var stream = fs.createReadStream(filepath, {
start : start,
end : end
}).on("open", function() {
stream.pipe(res);
}).on("error", function(err) {
console.log(err);
res.end(err);
});
});
});
app.listen(<port>, function () {
console.log('Listening on port <port>!');
});
Modified the file "Kodi\addons\webinterface.chorus\tpl\MovieView.html" under div id="movie-watch" so:
<div id="movie-watch" class="tab-pane">
<div class="col-1">
<video id="videoPlayer" controls width="100%" height="90%" preload="metadata">
<source src="http://<mydomain>:<port>/video?src=<%=encodeURIComponent(file) %>&movieId=<%= movieid %>" type="video/mp4">
</video>
<!--
<h2>HTML5 player</h2>
<p>Codec support is very limited in the browser.
H.264 video generally works but only with 2 channel audio. Works best in Chrome, may crash browser and/or XBMC!</p>
<div class="buttons">
Launch HTML5 player
</div>
<br />
<h2>VLC player</h2>
<p>VLC Player provides an
embeddable video player, it will play most videos, but does require you to
download and install extra software.
Works well in Chrome and Firefox.</p>
<div class="buttons">
Launch VLC player
</div>-->
Modified the file "Kodi\addons\webinterface.chorus\tpl\TvshowView.html" under div id="movie-watch" so:
<div id="tv-watch" class="tab-pane">
<div class="col-1">
<video id="videoPlayer" controls width="100%" height="90%">
<source src="http://<mydomain>:<port>/video?src=<%=encodeURIComponent(file) %>&episodeId=<%= episodeid %>" type="video/mp4">
</video>
<!--
<h2>HTML5 player</h2>
<p>Codec support is very limited in the browser.
H.264 video generally works but only with 2 channel audio. Works best in Chrome, may crash browser and/or XBMC!</p>
<div class="buttons">
Launch HTML5 player
</div>
<br />
<h2>VLC player</h2>
<p>VLC Player provides an
embeddable video player, it will play most videos, but does require you to
download and install extra software.
Works well in Chrome and Firefox.</p>
<div class="buttons">
Launch VLC player
</div>-->

$.ajax SOAP request is not working in Phonegap + JQM + IOS 6

Ajax to consume WCF service hosted at server. I already configured and allowed following flag of JQM to use Cross-Domain Requests.
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
The same code is working with Android emulator and Device. I also allowed the url in config.xml file of Phonegap for IOS app.
Also I can browse the same HTML page in Safari and IOS emulator. In both webservice is working fine. The issue occurs when I build and run the phonegap app in IOS emulator or device. The service will not called and success callback of $.ajax is called. I checked the response in success and I found that it is returning the HTML of web service url page (.svc).
I used following code to call SVC using $.ajax
var soapRequest = '<?xml version="1.0" encoding="utf-8"?>'
+ '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
+ '<soap:Body>'
+ '<SignIn xmlns="http://tempuri.org/">'
+ '<UserName>' + $.trim($('#txtEmail').val()) + '</UserName>'
+ '<Password>' + $.trim($('#txtPassword').val()) + '</Password>'
+ '<DeviceDetails>' + GetDeviceInfo() + '</DeviceDetails>'
+ '</SignIn>'
+ '</soap:Body>'
+ '</soap:Envelope>';
$.ajax({
beforeSend: function (xhr) {
ShowLoading('Please wait...');
xhr.setRequestHeader("SOAPAction", "http://tempuri.org/IService/SignIn");
}, //Show spinner
complete: function () {
HideLoading();
}, //Hide spinner
url: "http://somedomain/service.svc",
type: "POST",
dataType: "xml",
data: soapRequest,
contentType: "text/xml; charset=\"utf-8\"",
success: function (rcvdata, status) {
alert(rcvdata); // THIS IS GIVING HTML OF SERVICE PAGE
},
error: function (request, status, error) {
alert(request + "\n" + status + "\n" + error);
HideLoading();
}
});
I also tied to change the value of async and processdata option of AJAX but it is always returning the svc service page html. Ajax request status is always 200.
This issue is only occurring in Phonegap IOS app. When I directly open the HTML page in IOS emulator browser then the service is called successfully and I got the valid SOAP response.
I am using Phonegap 2.8.1 and also tried in 2.9.0
Thanks in advance.
Edit --------------
I host the WCF service local environment in IIS then it is working fine and I got the response from service. I also checked and compare the IIS settings in local and live server. Both are same

How can I integrate FusionChart in my SPA application developed using Durandal and Knockout?

How can I integrate FusionChart in my SPA application developed using MVVM architecture, Durandal and Knockout.js? I had created a simple HTML file, with hard coded data, in which the charts are working fine but I am not able to figure out how can I embed this code with my SPA Application.
I am sharing some details:
I have added following Js file in my HTML file :
<script type="text/javascript" src="./FusionCharts.js"></script>
<script type="text/javascript" src="./jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="./lib.js"></script>
My HTML file code in which fusion chart is rendered successfully is as follows :
<div id="chartdiv" align="center">Chart will load here</div>
<script type="text/javascript">
var chart = new FusionCharts("Column3D", "myChartId", "300", "200");
chart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"<styles>" +
"<definition>" +
"<style name='myCaptionFont' type='font' align='right'/>" +
"</definition>" +
"<application>" +
"<apply toObject='Caption' styles='myCaptionFont' />" +
"</application>" +
"</styles> " +
"</chart>");
chart.render("chartdiv");
</script>
I am not able to figure out what should be the code in my ViewModel.js, and view.html file to render FusionChart.
Please Help.
I developed a working demo for including FusionCharts in DurandalJS. Just copy the project to a webserver and access the app.
https://github.com/bhargav3/fcdurandal
First thing is to include fusioncharts.js which can be done using requirejs or by directly adding it in the index file. To avoid creating duplicate charts we shall check if the FusionCharts('myChartId') exists and avoid redraws.
Your viewmodel will look something like this,
define(['durandal/http', 'durandal/app'], function() {
return {
displayText: 'FusionCharts in a SPA app!',
viewAttached: function(view) {
if (typeof FusionCharts('myChartId') === 'undefined') {
$('#binder').append('<div id="chartContainer"></div>');
var myChart = new FusionCharts("Column3D", "myChartId", "400", "300", "0");
myChart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"</chart>");
myChart.render("chartContainer");
}
}
};
});
Where as your view will look like
<h2 data-bind="html:displayText"></h2>
<div id="binder"></div>
main.js is the bootstrap file and you can add your routers(for navigation) there.
If your JavaScript files are added via script tags on index.html, then Fusion Charts should be available to use from your view model. There is a way to utilize require.js to dynamically load into the scope of your view model if there was a reason you don't want it globally. I didn't include that below in the view model example in order to keep it simple to demonstrate the use of viewAttached.
viewAttached (http://durandaljs.com/documentation/Hooking-Lifecycle-Callbacks/) seems to be the last method called in the lifecycle. As the documentation indicates, the method indicates when the "view is attached to the parent DOM node." This should allow you to manipulate the view as needed after binding has occurred. See also: http://durandaljs.com/documentation/Interacting-with-the-DOM/
Below is an example of using viewAttached in your view model:
define(function() {
var activate = function() {
};
var viewAttached = function() {
var chart = new FusionCharts("Column3D", "myChartId", "300", "200");
chart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"<styles>" +
"<definition>" +
"<style name='myCaptionFont' type='font' align='right'/>" +
"</definition>" +
"<application>" +
"<apply toObject='Caption' styles='myCaptionFont' />" +
"</application>" +
"</styles> " +
"</chart>");
chart.render("chartdiv");
};
return {
activate: activate,
viewAttached: viewAttached
};
};
Finally, your view should contain:
<div id="chartdiv" align="center">Chart will load here</div>

Facebook Authentication with JSP

I'm trying to complete Facebook Authentication within a simple JSP page following this example: http://www.sergiy.ca/how-to-implement-facebook-oauth-2.0-app-authorization-process-in-java/
Unfortunately, I'm not very successfull at this point. Your help would be appreciated. As developer of the app, I somehow managed to accept the app and I can see it in my app list. But when I log in as another user, I'm unable to accept the app. The user is not prompted to give access right to the app although the redirect request seems to have been sent to FB. Any help would be much appreciated. My code:
<%# page import="java.util.*,org.apache.commons.codec.binary.*, java.net.*, org.json.simple.*" %>
<html>
<body>
<%
String fbSecretKey = "efqec6fdedd17a64055712dcc7d81f58";
String fbAppId = "116041890091";
String fbCanvasPage = "http://apps.facebook.com/stupidgame/";
String fbCanvasUrl = "http://stupidgame.com:8090/stupidgame/";
String accessToken;
if(request.getParameter("signed_request") != null) {
//it is important to enable url-safe mode for Base64 encoder
Base64 base64 = new Base64(true);
//split request into signature and data
String[] signedRequest = request.getParameter("signed_request").split("\\.", 2);
//parse signature
String sig = new String(base64.decode(signedRequest[0].getBytes("UTF-8")));
//parse data and convert to json object
JSONObject data = (JSONObject)JSONValue.parse(new String(base64.decode(signedRequest[1].getBytes("UTF-8"))));
//check if user authorized the app
if(data.get("user_id")==null || data.get("oauth_token")==null) {
//this is guest, create authorization url that will be passed to javascript
//note that redirect_uri (page the user will be forwarded to after authorization) is set to fbCanvasUrl
response.sendRedirect("https://www.facebook.com/dialog/oauth?client_id=" + fbAppId +
"&redirect_uri=" + fbCanvasUrl + "&scope=publish_stream,offline_access,email");
return;
}
accessToken=data.get("oauth_token")+"";
}else{
response.sendRedirect("https://www.facebook.com/dialog/oauth?client_id=" + fbAppId +
"&redirect_uri=" + URLEncoder.encode(fbCanvasUrl, "UTF-8") +
"&scope=publish_stream,offline_access,email");
return;
}
System.out.println("All set with accessToken:"+accessToken);
%>
</body>
</html>
Since you app is running in an iframe "response.sendRedirect" only redirects the iframe and the auth dialog needs to be the whole page.
Replace:
response.sendRedirect(...)
with:
%><script language="JavaScript"> top.location.href = "<%=auth_url%>"; </script> <%
Or something similar and it should work.
The javascript should be similar to the php docs https://developers.facebook.com/docs/authentication/