i need to show a pdf file located in a URL
My code is easy...
var link_condiciones;
var idioma = Left( Titanium.Locale.getCurrentLanguage().toLowerCase(),2 );
if( idioma == "es" ) {
link_condiciones = "http://micoachingapp.net/webpanel/archivos/viewTermsES.html";
}
else{
link_condiciones = "http://micoachingapp.net/webpanel/archivos/viewTermsEN.html";
}
Ti.API.info("*** Link: " + link_condiciones );
// Creamos la ventana
var winCondiciones = Ti.UI.createWindow({
backgroundColor: clr_aux4,
extendEdges:[Ti.UI.EXTEND_EDGE_TOP],
barColor: clr_primario_fuerte,
tintColor: clr_primario_suave,
title: " ",
titleControl: Ti.UI.createImageView({ image: 'images/tituloSuperior.png' }),
rightNavButton: Ti.UI.createImageView({ image: 'images/dummy.png', width: 35, height: 35, borderRadius: 5 })
});
// Construimos el visor Web
var WebView = Ti.UI.createWebView({
top: '30dp',
width: Ti.UI.FILL,
height: Ti.UI.FILL,
url: link_condiciones
})
winCondiciones.add(WebView);
var btnAceptar = Ti.UI.createButton({
title: L("txt_acepto_terminos"),
borderRadius: radioArcoBoton,
backgroundColor: color_on,
color: 'white',
height: '7%',
bottom: 3,
width: '95%'
})
btnAceptar.addEventListener("click", function(){
RegistrarFecha( fecha, navWindow, winCondiciones, winAnt1, winAnt2 );
});
winCondiciones.add(btnAceptar);
// Mostramos la ventana
if(IsAndroid()) {
winCondiciones.open();
}
else {
navWindow.openWindow(winCondiciones);
}
But i cant see the PDF, only a lote of erros in the console.
[INFO] : TiUIWebView: (main) [2621,15443] Detected com.htc.software.Sense feature com.htc.software.Sense7.0
[INFO] : WebViewFactory: Loading com.google.android.webview version 51.0.2704.81 (code 270408100)
[INFO] : cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 7860-7862)
[INFO] : cr_LibraryLoader: Expected native library version number "51.0.2704.81", actual native library version number "51.0.2704.81"
[INFO] : cr_LibraryLoader: Expected native library version number "51.0.2704.81", actual native library version number "51.0.2704.81"
[INFO] : chromium: [INFO:library_loader_hooks.cc(143)] Chromium logging enabled: level = 0, default verbosity = 0
[INFO] : cr_BrowserStartup: Initializing chromium process, singleProcess=true
[ERROR] : ApkAssets: Error while loading asset assets/natives_blob_64.bin:
...
[INFO] : *** Lenguaje: es
[INFO] : *** Valor : 2016-08-12 18:00:00
[INFO] : *** Link: http://micoachingapp.net/webpanel/archivos/viewTermsES.html
[INFO] : TiUIWebView: (main) [48206,288996] Detected com.htc.software.Sense feature com.htc.software.Sense7.0
[WARN] : cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
[INFO] : cr_Ime: ImeThread is not enabled.
[ERROR] : SensorManager: uid = 10142
[INFO] : SensorManager: registerListenerImpl: listener = android.view.OrientationEventListener$SensorEventListenerImpl#31ca6080, sensor = {Sensor name="BMA255 3-axis Accelerometer", vendor="Bosch", version=1, type=1, maxRange=39.24, resolution=0.15328126, power=0.2, minDelay=10000}, delay = 200000, handler = null
[WARN] : cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 21108
[WARN] : cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 21108
that's the ful code with the problem.
Its only a window, with a pdf and a button.
Appelerador, SDK 5.3.1 GA
Android 5
you can try this.
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
WebViews can't display pdfs natively. You can try loading the url through a web based pdf reader like google docs, but you can't just display a pdf in a webview. I'm not sure why you thought you could, a WebView displays web pages, not pdfs.
Suppose your url is this:
http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf
1 - Either open the link in external browser:
Ti.Platform.openURL('http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf');
2 - Assuming that your URL directly displays the pdf file as above url, you can get the binary data using Ti.Network.HTTPClient and then you can display it in webview like this:
var url = "http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf";
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
var pdfData = this.responseData; // it contains the pdf blob data
// Construimos el visor Web
var WebView = Ti.UI.createWebView({
top: '30dp',
width: Ti.UI.FILL,
height: Ti.UI.FILL,
data : pdfData // instead of url, use pdfData blob object
});
winCondiciones.add(WebView);
},
onerror : function(e) {
Ti.API.error(e.error);
alert('error');
}
});
client.open("GET", url);
client.send();
3 - Try this also as I was also stuck in some weird issue once and after finding no help, it worked finally by adding borderRadius attribute:
// Construimos el visor Web
var WebView = Ti.UI.createWebView({
top: '30dp',
width: Ti.UI.FILL,
height: Ti.UI.FILL,
borderRadius : 2,
url: link_condiciones
});
winCondiciones.add(WebView);
If it doesn't work out for you, then you probably try to look out some module to display remote pdf file. Good Luck!!!
As I tried to run the code, the issue you are facing can be solved by putting complete url of what you provided in one of your comment.
Put this :
http://micoachingapp.net/webpanel/archivos/viewTermsES.html
instead of micoachingapp.net/webpanel/archivos/viewTermsES.html
Now, what I saw weird is that if I open up this url http://www.micoachingapp.net/webpanel/archivos/viewTermsES.html, I wonder why it takes me to some other pdf by simply adding www in it.
Carefully look at the all URLs I mentioned above, here are these:
Yours - micoachingapp.net/webpanel/archivos/viewTermsES.html
If you paste your URL in any browser and then you will copy it again from the address bar, you will get this: http://micoachingapp.net/webpanel/archivos/viewTermsES.html
Now add www - http://www.micoachingapp.net/webpanel/archivos/viewTermsES.html
In WebView
URL 1 shows the error you mentioned in your question.
URL 2 is the actual url as displayed by chrome or safari or any desktop browser.
URL 3 takes to some other pdf...How is that possible???
So your solution lies within these 3 URLs, maybe it is a domain issue or don't know what it is as I never faced such issue.
But for sure, it will work if you open it in external device browser using Ti.Platform.openURL
Related
I have an android application that sends the camera stream through a webview through peerjs (webrtc) the web application on the browser receives the video and streams it.
Things are working but the video on the web is too slow and the image freezes for some time before getting the second image...
Is there a way to make the resolution lower ? or buffer the video on the web application ? or can it be something wrong with my implementation ?
Android Webview code:
initVideo = function(videoSourceValue) {
var video = document.querySelector('video');
navigator.getUserMedia({video: {optional: [{
sourceId: videoSourceValue
}]
}
},function(stream) {
video.src = window.URL.createObjectURL(stream);
$('#peerId').text("calling : " + SERVER_PEER_ID);
var mediaConnection = peer.call(SERVER_PEER_ID, stream);
mediaConnection.on('stream', function(remoteStream) {
// Show stream in some video/canvas element.
});
},function(e){
console.log('failed',e);
});
}
Web part:
function getVideoStream() {
PEER.on('call', function(call) {
var mediaConnection = navigator.getUserMedia({video: true}, function(stream) {
call.answer(stream); // Answer the call with an A/V stream.
call.on('stream', onReceiveStream);
}, function(err) {
console.log('Failed to get local stream' ,err);
});
});
}
function onReceiveStream(stream){
console.log('received stream');
$('video').prop('src',window.URL.createObjectURL(stream));
}
Thanks
Update 1
I tried to add {reliable : true}, still having the same issue.
I'm also sending location data to the server, and it seems that the video streams and location data are sent together periodically (the chart on the web showing speed and the video move at the same time) but the frame rate is too slow.
When you establish the video/audio stream you can specify some constraints...
var videoOptions = (isCordova) ? {audio: true, video: true} :
{ audio: true,
video: {
mandatory: {
maxWidth: 640,
maxHeight: 360,
// maxAspectRatio:4/3,
// maxFrameRate:1
},
quality: 7,
width: { ideal: 320 },
height: { ideal: 240 }
}
};
navigator.getUserMedia(videoOptions, function (stream) {
In the above code, if you are on a device (android/ios) you don't get to choose, but you can control it on the browser. A quality of 5 is the level that the video driver author deemed as an acceptable trade off between quality and bandwidth. Limiting the dimensions of the picture helps too.
See this link for mode details: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
My issue was completely unrelated to bandwidth, I simply didn't put autoplay on the video tag , so the video was only refreshing when a redraw was happening.
Thanks a lot for your answers they really give insight on how things work in webrtc.
I'm trying to use the youtube iframe player inside an android WebView but it fails on android 4.x while on 5.x everything works great.
When I try it in 4.x the player loads the video, when I start it I see nothing but hear the video sound.
The logcat gets filled with chromium error messages over and over again:
E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5942)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUseProgram: program not linked
E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUniformMatrix4fv: wrong uniform function for type
E/chromium(20362): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5db83bb8]GL ERROR :GL_INVALID_OPERATION : glUniform1iv: wrong uniform function for type
Here's how I set the WebView:
this.webview = (WebView) this.findViewById(R.id.webview);
WebSettings settings = this.webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(false);
this.webview.setWebChromeClient(new WebChromeClient());
...
this.webview.loadUrl(ADDRESS_OF_PAGE);
Also, I enable hardware acceleration in the manifest:
<application
...
android:hardwareAccelerated="true">
Here's the js part:
var player;
var VIDEO_ID = "EIsauUFIguE";
window.onYouTubeIframeAPIReady = function() {
console.log("youtube api ready, loading player");
player = new YT.Player("playerIframe", {
width: "100%",
height: "100%",
videoId: null,
events: {
onReady: onPlayerReady,
onStateChange: onPlayerStateChange,
onPlaybackQualityChange: onPlayerPlaybackQualityChange,
onError: onPlayerError
},
playerVars: {
modestbranding: 1,
playsinline: 1,
fs: 0,
showinfo: 0
}
});
}
function onPlayerReady(event) {
console.log("player is ready: ", event);
playVideo();
}
function onPlayerStateChange(event) {
console.log("player state change: ", event);
}
function onPlayerPlaybackQualityChange(event) {
console.log("player playback quality change: ", event);
}
function onPlayerError(event) {
console.log("player error: ", event);
}
function playVideo() {
console.log("playing video: " + VIDEO_ID);
player.loadVideoById(VIDEO_ID);
player.setPlaybackQuality("medium");
}
function loadPlayer() {
console.log("loading youtube api");
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
loadPlayer();
Any idea why it behaves this way and only in android 4.x?
Thanks.
I had the same problem, but after fighting with this long time, i didn't find a solution. I tested all the configurations with webview and did many different html changes to put the iframe.
After my researching i only can add:
In Android 4 versions, can't autoplay. The user has to press play button into the iframe to start play the video. Particularly:
In Android 4.1 it reproduces the audio but not the image.
In Android 4.3 i tested in devices which can reproduce audio but no video and devices that can't reproduce anything.
In Android 4.4 don't reproduce anything
From Android 5 and + everything works fine.
Good luck and I plus vote this question to know if anyone can put light into this question :)
this code returns:
Cannot read property 'getPicture' of undefined
Have no idea what im doing wrong, can you please help me with the code?
My App:
angular.module('Todo', ['ionic', 'Todo.controllers','ngStorage',
'Todo.services', 'ngCordova'])
my Controller:
.controller('profileEditCtrl', function($scope,Camera, $localStorage,
$cordovaCamera)
{
$scope.$storage = $localStorage.$default({ data:[]});
$scope.takePicture = function()
{
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL });
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src ="data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
}});
Your code is correct, just add an html button with ng-click="takePicture()".
There is no problem here, It's sure that the browser "cannot read
property 'getPicture' of undefined" because it has no configuration
for a mobile camera that you defined, which means you should test your application on
a real device using:
> ionic run android.
Notice that the new update of Google Chrome has a new feature which
helps your test your device on the browser if it is connected to the
PC/laptop, for testing go to chrome's navigation panel >> More tools >> Inspect devices
or just go to this link:
chrome://inspect/#devices
I'm sure your camera will function normally if you have the plugin cordova plugin add org.apache.cordova.camera installed in the app,
I hope this helps you.
After trying various solutions with no luck for my cordova project, I simply went ahead to use the built-in JavaScript APIs. Essentially:
async function startCapturing() { // get ready to shoot
await getPermission('android.permission.CAMERA');
let stream = await navigator.mediaDevices.getUserMedia({ video: {width: 480, height: 320, facingMode:'environment' }, audio: false });
let video = document.getElementById("pVideo"); // a <video> element
video.srcObject = stream;
video.play();
video.style.display = "block";
}
function shootPhoto(){ // take a snapshot
let video = document.getElementById("pVideo");
let canvas = document.getElementById("pCanvas"); // a <canvas> element
let context = canvas.getContext('2d');
context.drawImage(video,0,0,480,320);
document.getElementById('fsPhotoI').src = Photo.current.src = canvas.toDataURL('image/png');
Photo.current.changed = Profile.current.changed = true;
video.style.display = "none";
}
In particular, some plugins did not work for me because they could't use the Android rear camera right away. The following in getUserMedia(...) does the trick:
facingMode:'environment'
Also make sure you have the CAMERA permission in your AndroidManifest.xml.
I encountered a problem when I try to package my sencha-touch app using phonegap. Everything works fine except accessing WFS in phonegap. (And the app has no problem running in browser, WFS access is OK)
My phonegap version is 2.9; openlayer version is 2.13
Here I present my simple code. You can also check the example codes in the following site: http://openlayers.org/dev/examples/wfs-filter.html
var rootUrl = window.location.protocol + "//" + window.location.host + '/';
var map;
function init() {
map = new OpenLayers.Map({
div: "map",
layers: [
new OpenLayers.Layer.WMS(
"Natural Earth",
"http://demo.opengeo.org/geoserver/wms",
{ layers: "topp:naturalearth" }
),
new OpenLayers.Layer.Vector("WFS", {
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.WFS({
url: rootUrl + 'proxy.py?url=http://demo.opengeo.org/geoserver/wfs',
featureType: "tasmania_roads",
featureNS: "http://www.openplans.org/topp"
}),
styleMap: new OpenLayers.StyleMap({
strokeWidth: 3,
strokeColor: "#333333"
}),
})
],
center: new OpenLayers.LonLat(146.7, -41.8),
zoom: 6
});
}
In phonegap there's no problem accessing WMS, but when I try WFS, it never work.
Comparing to the link I showed you before, there's a road displayed in the map, and it is obtained through WFS. In my phonegap app, the road will not be displayed.
I'm wondering whether it is a WFS issue, or phonegap issue. Something is blocking my access to WFS in my phonegap app.
Please give me some suggestions and hints, guys! I will really appreciate it.
function getLayerList() {
$.ajax({ url: rootUrl + 'proxy.py?url=http://192.168.0.23/LBEService/Service1.svc/GetEventList',
//async: false,
data: JSON.stringify({}),
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
console.log(result);
$("#demo").html(result[0].event_NAME);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
}).done(function () {
});
}
Have you added the domain that is hosting the WFS to the white list?
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html
On android PhoneGap window.location.protocol is 'file:' and window.location.hostname is "", so your app will probably be looking for file://proxy.py? which doesn't exist on your device.
To solve this issue I test the protocol, and set up OpenLayers.Proxy accordingly, thus:
if( location.protocol == 'file:' ) {
OpenLayers.ProxyHost = "";
} else {
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
}
So in your case, if protocol is 'file:', I think you need to drop 'proxy.py?'
Tip: debug your android app using Chrome on your PC (chrome://inspect/#devices) and you'll see the request that android is making.
I have the following code:
app.js:
Ti.include('logic/ui.js');
/* some code */
mainWindow.open();
ui.js:
var mainWindow = Ti.UI.createWindow({
title : 'Main Window',
backgroundColor:'transparent',
exitOnClose : true,
backgroundImage: 'view/i/bg.png',
});
var resultWebView = Titanium.UI.createWebView({
url : 'view/result.html',
backgroundColor: 'transparent'
});
mainWindow.add(resultWebView);
Problem: On devices with Android < 2.3.5, WebView does not load when the application is first loaded. But if you apply zoom, it works fine. Any ideas on how I can resolve this?
UPDATE:
If the url to the web document is internet url, then WebView always displayed without a problem.
var resultWebView = Titanium.UI.createWebView({
url : 'http://www.google.com',
backgroundColor: 'transparent'
});