Android doesn't load my webView - android

I want to load my webView which url is http://pickalize.info:4000 and using a lot of javascript.
So I write code like this.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView webView = (WebView)findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("http://pickalize.info:4000/");
}
I tried change url to http://www.google.co.jp then it show the page correctly.
But my site doesn't show up.
Why it doesn't show my site?
Do you have any idea? Thanks in advance.

Can you double-check in the web browser on your Android device that your web site is listening on port 4000 - it seems to be listening on port 80 (the default port for HTTP).
When I visit your web site on the default port e.g. http://pickalize.info/ then I get a web page that includes a list of URLs. Note: http://pickalize.info:80/ is equivalent to above and loads the same web page I see without the port number in the URL.
The page has the following text:
Pickalize
Iphone Apps
Profile
Others
RSS
no valid 'aps-environment' error 2013-03-02
ノートを買った 2013-03-02
JavaでJSON 2013-03-01
もしかして 2013-03-01
半日で作ったしょぼいアプリがリリースされた 2013-02-27
WordBench香川に行ってきた 2013-02-25
Apple's game center problem. 2013-02-24
observer 2013-02-21
ナビゲーションバーを作ってみた。 2013-02-21
My App has rejected. 2013-02-20
プログラミングを始めて20ヶ月経って(経過) 2013-02-18
Python のスクリプトをどこでも実行する 2013-02-17
やっと... AppStoreに提出できた 2013-02-17
iOS開発のために画像を編集するやつ作った. 2013-02-17
Admobを埋め込む注意点 2013-02-16
Flaskで自分だけのブログを作った。 2013-02-15
I get similar content in a mini Android app I just created that uses your sample code. To make sure it copes with port numbers in the URL I made the following minor change:
webView.loadUrl("http://pickalize.info:80/");
However when I try to visit your web site using port 4000 I get a message telling me the web site is not available. I have tried from my Android device and my laptop. There doesn't appear to be a site listening / hosted on port 4000; there does seem to be a site on port 80.
Please double-check your site is being hosted on port 4000 and that you can reach it from a computer that's using the internet to connect to the site (in case there are router or firewall restrictions that block traffic to port 4000).
PS: The web page on port 80 has minimal javascript, from view source in my laptop web browser, this is what I can see
<script src="/static/js/rainbow.js"></script>
<script src="/static/js/languages/javascript.js"></script>
<script src="/static/js/languages/generic.js"></script>
<script src="/static/js/languages/python.js"></script>
<!--google analytics-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15508754-4']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
// google feed
google.load("feeds","1");
var init = function(){
};
google.setOnLoadCallback(init);
</script>

Related

HTML Camera API in Android webview

I'm using the following html code. I'm able to get a video stream on my desktop, but I'm getting a grey play button in the android webView app. I'm serving this over a https connection.
Please guide me as Im new to both of these code snippets.
HTML
<div id="video-container">
<video id="camera-stream" width="500" autoplay></video>
</div>
Script.js
window.onload = function() {
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true },
function(localMediaStream) {
var vid = document.getElementById('camera-stream');
vid.srcObject = localMediaStream;
},
function(err) {
console.log('The following error occurred when trying to use getUserMedia: ' + err);
}
);
} else { alert('Sorry, your browser does not support getUserMedia'); }
}
This screenshot is taken from my desktop chrome browser.
and this is taken from my phone webView.
I know this is an old thread but I recently run into the same issue and only after a lot of tries I finally found the solution.
If you see this play button all the permission should be set correctly.
It seems that the webview is waiting for an user interaction to start the stream but tapping on the icon does not starts the video (idk how the user should "approve" the streaming)
The solution is to change the setting of the webview in you webapp:
webView.settings.mediaPlaybackRequiresUserGesture = false;
In this way the stream starts correctly without any user interaction

Websocket not working on my Android app (with Phonegap Build)

I tried to develop a simple mobile application that connect to a websocket server. I used Phonegap Build to make my Android .apk, here's the html code :
<html>
<head>
<title>Testing websockets</title>
</head>
<body>
<div id="messages"></div>
<script type="text/javascript">
var webSocket =
new WebSocket('ws://192.168.82.1:8080/WebSocket/websocket');
webSocket.onerror = function(event) {
onError(event)
};
webSocket.onopen = function(event) {
onOpen(event)
};
webSocket.onmessage = function(event) {
onMessage(event)
};
function onMessage(event) {
document.getElementById('messages').innerHTML
+= '<h1 align="center"/>' +" "+ event.data;
}
function onOpen(event) {
document.getElementById('messages').innerHTML
+= '<h1 align="center"/>connection established';
}
function onError(event) {
alert(event.data);
}
</script>
</body>
</html>
The code is working fine on my navigator but the message "connection established" doesn't even appear when I use the Android app.
Is there something wrong with this code or does my app need some library ?
PS : I have another code with a button sending a message to the server and receiving a text from it, and of course it's the same problem !
WebSockets are only supported in WebView after Android 4.4. So if you want to use it in older android versions ,you have some choices:
Use a Cordova plugin that provides that functionality. For example, https://github.com/knowledgecode/WebSocket-for-Android (this is just an example, I have never worked with that plugin)
Use something like SockJS or socket.io to provide webSockets when supported and fallback to other technologies when not. Please note that using those technologies requires you to use them also in the server

Android web browser not writing cookie in desktop view

Okay, so I am using a cookie to generate mobile content on different device widths. Basically the site looks one way on desktop and reveals post content on the mobile under 800px.
Everything is working perfectly except for one little issue. When I switch to desktop view in a mobile browser, seems to only be happening in iOS safari and android HTC Internet, the cookie is not being applied to the content isnt being generated. Ive tried numerous searches and suggestions across the web and havent found anything. Any help would be amazing.
Script in header:
<script type="text/javascript">var mql = window.matchMedia("screen and (max-width: 800px)")
if (mql.matches){ var setCookie = function setCookie(name) {
document.cookie = 'distanceMobile=1; expires=0; path=/';
}
setCookie('distanceMobile');}
else{
// do something else
}</script>
<script type="text/javascript">
var mql = window.matchMedia("screen and (min-width: 801px)")
if (mql.matches){ var delete_cookie = function delete_cookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
delete_cookie('distanceMobile');}
else{
// do something else
}
</script>
Php for the template:
<?php
// Template Name: Full Width Home
get_header("home");
if ( wp_is_mobile($_COOKIE['distanceMobile']) ) {
echo '<style scoped> #media screen and (min-width: 801px){
#content {display: none !important;}
}</style>';
get_template_part('custom-home-content');
//echo "Hello!";
} elseif ($_COOKIE['distanceMobile']) {
get_template_part('custom-home-content');
//echo "Hello!";
} else {
// do nada
}
get_footer(); ?>
Here is a link to the site im working on. If you shrink your browser window below 800 you will have to give 2 quick refreshes for it to print the content. Otherwise visiting on a device it will just load fine.
Again ive tried multiple things so far. I tried stripping away everything matchMedia and ive tried doing an alert. It seems to just not be working in the mobile browser when you click desktop view.
Regards.
* Update PHP file to test if mobile is recognized and cookie firing*
Im returning the SPM in desktop view in the mobile browser
<?php
// Template Name: Full Width Home
get_header("home");if ( wp_is_mobile() ) {
get_template_part('custom-home-content');
//echo "Hello!";
}
elseif ($_COOKIE['distanceMobile']) {
get_template_part('custom-home-content');
//echo "Hello!";
}
else {
echo "SPM JR.";
}
get_footer(); ?>

Android barcode scanner integration with web page

I have been researching all morning about integrating an android barcode scanner app into a web page, but haven't found exactly what I need to know. I want to have a web page that the user can fill in text fields by using an android barcode scanner. So the user would be on a web page and would either click inside the text field or click a button next to the text field that would start the android barcode scanner. They would then scan the barcode and the text field would be filled in.
I have found solutions on how to do this and then go to a different page, but it is important that the user stays on the same page. I have seen the zxing project and thought that might be able to be used, but I'm not sure if it allows for the page to stay the same.
I'm pretty sure this is possible and is wondering if any one could give me a high level overview on how they would do it. I was thinking it might be able to be done with an ajax request that gets submitted on a button click. The ajax request would get sent to my server, the server would send something to the android device that would start the scanner and return the data which in turn gets sent back in the ajax response. Is there any way to cut out the server though and just have the android browser starting the barcode scanner? Thank you for your time and I appreciate any discussion on it.
ZXing (zebra crossing) provides the capability to initiate the bar code scanner via a webpage through a button click event, anchor tag, or other action that could call a URL on a mobile device.
When the barcode scanner application is installed on an android device, a URL call to:
zxing://scan/?ret=http://foo.com/products/{CODE}/description&SCAN_FORMATS=UPC_A,EAN_13
Will bring up the device bar code reader, the user scans the code, and the code is returned via the callback URL parameter supplied in the zxing URL.
You can view an example (works on android) here: http://zxing.appspot.com/scan
You can try this for Android:
You can use Zxing library for barcode scan for webpages
<!DOCTYPE html>
<script type="text/javascript">
//This entire block of script should be in a separate file, and included in each doc in which you want scanner capabilities
function zxinglistener(e){
localStorage["zxingbarcode"] = "";
if(e.url.split("\#")[0] == window.location.href){
window.focus();
processBarcode(decodeURIComponent(e.newValue));
}
window.removeEventListener("storage", zxinglistener, false);
}
if(window.location.hash != ""){
localStorage["zxingbarcode"] = window.location.hash.substr(1);
self.close();
window.location.href="about:blank";//In case self.close is disabled
}else{
window.addEventListener("hashchange", function(e){
window.removeEventListener("storage", zxinglistener, false);
var hash = window.location.hash.substr(1);
if (hash != "") {
window.location.hash = "";
processBarcode(decodeURIComponent(hash));
}
}, false);
}
function getScan(){
var href = window.location.href.split("\#")[0];
window.addEventListener("storage", zxinglistener, false);
zxingWindow = window.open("zxing://scan/?ret=" + encodeURIComponent(href + "#{CODE}"),'_self');
}
</script>
<html>
<head>
<script type="text/javascript">
function processBarcode(b){
var d = document.createElement("div");
d.innerHTML = b;
document.body.appendChild(d);
}
</script>
</head>
<body>
<button onclick="getScan()">get Scan</button>
</body>
</html>
For reference: Read link
Using a javascript interface and loadurl(javascript...) you can communicate with your webpage from Android
public void loadScript(String script){
webview.loadUrl("javascript:(function() { " + script + "})()");
}
private class JavaScriptInterface {
public void startQRScan() {
...
}
}
There are plenty of examples on google.

jQuery ajax json request not working over mobile network

Ive been scratching my head with this for a few days now.
I have written a mobile specific website using plain old html and jquery.
It used ajax with json responses to get data from a service written using service stack.
all works perfectly fine from desktop and lots of different mobile i have tried (android, iphone, bb etc)
However there seems to be a specific issue with my handset (Samsung Galaxy S2 on vodafone)
When the handset is on wifi the ajax works perfectly and the json object is received from the service and processed correctly.
However when on mobile data the response does not come back as json but as the service stack web page (it looks like its not being told to return json correctly)
Im wondering if the headers could be being stripped out by vodafone or someting?
this is the ajax call being used
$.ajax({
url: sgee.ApiUrl + "/api/GetRegionId/" + sgee.App.postcode,
type: 'GET',
dataTye: 'json',
contentType: "application/json;charset=utf-8",
cache: false,
success: function (data) {
if (data.success) {
sgee.App.EnquiryId = data.enquiryId;
sgee.App.RegionId = data.regionId;
sgee.App.RegionName = data.regionName;
$("#regionTxt").html("We have identified that you live in the " + sgee.App.RegionName + " supply region.");
sgee.EndLoading(250);
sgee.HideStep(2);
} else {
sgee.SetValidationError("#pcodeControl", "Please enter a valid UK postcode");
}
},
error: function () {
sgee.SetValidationError("#pcodeControl", "Please enter a valid UK postcode");
sgee.SendError("Error on /api/GetRegionId/", "sgee.Step1");
},
complete: function () {
}
});
This is the data expected
{"postCode":"s63","regionId":14,"regionName":"YORKSHIRE","enquiryId":578106,"success":true,"returnedId":0}
and when running on mobile this is what i am receiving (ill not include the whole as it is long but it is just the html response as if i hadnt set the response type or browsed to the page)
<!doctype html>
<html lang="en-us">
<head>
<title>GetRegionId Snapshot of 03/08/2012 13:59:50</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
This really is driving me mad as it is impossible to debug (at least i cant find a way) i am using the android chrome remote developer tools to step through code but i cant capture the http request and response as it is on the mobile network.
Just guessing... But you're expecting json content right? If so, why is your response "text/html" instead of "application/json"?
You have a typo in there... "dataTye: 'json',". Could this be it?
I think is due to type of form submission. use post instead of get...

Categories

Resources