Phonegap/Cordova InAppBrowser not launching - javascript

I am not sure why but when I do the following
<img id="buttons" src="https://qikout.com/apppics/MerchantPromo.png" style="margin:1% auto; width:99% !important;" onclick="openextlink('https://qikout.com');"/>
function openextlink(url)
{
var ref = window.open(url, '_blank', 'location=no');
//window.plugins.childBrowser.showWebPage(url, { showLocationBar: true });
}
it works fine. But when I want to run the openextlink from within another function it does not open the window, instead it loads the page but just does not show it to the user.
for e.g.
function scan(){
window.plugins.barcodeScanner.scan( function(result) {
if(result.format != "QR_CODE")
{
alert("That is not a valid google Tag");
}
else
{
n = result.text.split(".com/");
loadpet();
//alert("We got a barcode\n" +
// "Result: " + result.text + "\n" +
// "Format: " + result.format + "\n" +
// "Cancelled: " + result.cancelled);
}
}, function(error) {
alert("Scanning failed: " + error);
}
);
}
function loadpet(){
$("#buttons").trigger("click");
var link = "http://www.google.com/" + n[1];
openextlink(link);
}
it works via
<div onclick="scan();" class="menu-right"></div>
Basically it scans fine, it gets the result it moves the result to the loadpet function and even sends it to the openextlink function however does not popup the viewer.

Your window.open code looks right (based on how InAppBrowser works as of Cordova 3.0).
Can you confirm all of the following?
The InAppBrowser plugin has an entry in your /#myapp#/platforms/#platform#/www/cordova_plugins.js file?
The InAppBrowser plugin folder is in /#myapp#/platforms/#platform#/plugins/
The related SRC files for InAppBrowser are in the platform folder as well (for example IOS plugin src files are: /#myapp#/platforms/#platform#/#appname#/Plugins/)
Also if all the above are confirmed but still no luck you might try appending a console.log('inappbrowser.js file has loaded!') line to the end of your inappbrowser.js file to confirm it is indeed loading (assuming you have setup the debug console and can view the output).

Related

mp3 Download Ionic Framework | Android | HTML5

I am working on ionic framework for android .
It simply contains an Iframe to embed a website in a blank project.
This is the website http://www.ultrayoutube.com/ANDROID/#/wanna.
I am facing two problems
Making Iframe equal to size of screen
I want Iframe to be equal to the size of window . I am using <iframe src="http://www.ultrayoutube.com/ANDROID/#/wanna" style="width:100%; height:100%;" ></iframe>
But iframe only takes 1/2 of screen in emulator
When the user searches for the song he must be able to download it by clicking download mp3
I have gone through some plugins as file transfer plugins but they all need a download link to download something . I want it that when the user clicks on button download mp3 , that link is automatically passed to the plugin and is downloaded to user's cell phone .
on Document Head try to initialise your file transfer plugin
function onDeviceReady() {
console.log('deviceready');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
window.fs = fileSystem;
window.fileTransfer = new FileTransfer();
window.fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
console.log(perc + '%');
$('.progress-bar').css({width: perc + '%'});
}
};
window.fs.root.getDirectory('Download', {create: true}, function(dirEntry) {
window.downloadFolder = dirEntry;
});
},
function(evt) {
console.log(evt.target.error.code);
}
);
}
Change : script.js
app.run(function($rootScope, downloader, alertService) {
$rootScope.fs = window.fs;
$rootScope.downloadFolder = window.downloadFolder;
$rootScope.fileTransfer = window.fileTransfer;
$rootScope.messages = {}
...
$rootScope.saveContent = function(url) {
var uri = encodeURI(url);
$rootScope.fileTransfer.download(
uri,
$rootScope.downloadFolder.toURL() + "/" + url.substring(url.lastIndexOf('/') + 1),
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
}
);
};
...

Cordova's FileTransfer Writing Error (Code 1)

I'm using Cordova 4.2.0 for Android.
I have some troubles to get FileTransfer plugin work properly. I suppose that there is a writing error
exception:".myApp\/contentImages\/20150110220101.jpg: open failed: ENOENT (No such file or directory)"
filename was previously tested and does not exist yet:
rootFS.getFile('.myApp/contentImages/'+file,{create:false},
function(){
console.log(file+' already exists');
},
function(error){
console.log(file+" does not exist locally");
console.log("Error #"+error.code);
download(file);
}
);
And here is the download function:
function download (filename){
var localPath = rootFS.fullPath+'/.myApp/contentImages/'+filename;
var fileTransfer = new FileTransfer();
fileTransfer.download(
encodeURI('http://distantApp/contentImages/'+filename), // This file exists
localPath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log('download error: ' + error.code + ": "+error.exception+" ; source " + error.source+" ; target " + error.target);
}
);
}
What could be the problem?
EDIT
Code for rootFS
function onDeviceReady(){
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function(){
console.log("error requesting LocalFileSystem");
});
}
function gotFS(fileSystem) {
console.log("got filesystem: "+fileSystem.name); // displays "persistent"
console.log(fileSystem.root.fullPath); // displays "/"
window.rootFS = fileSystem.root;
}
The problem was caused by an upgrade of Cordova from a previous version.
The path of local files was not properly identified: .fullPathis now obsolete and should be replaced by .toURL().
I think your problem is not with FileTransfer plugin, but the way you are trying to check if the file exists.
Looking here: http://www.html5rocks.com/en/tutorials/file/filesystem/ you we'll see that accessing to a file which its immediately parent does not exist raise an exception:
Inside the callback, we can call fs.root.getFile() with the name of the file to create. You can pass an absolute or relative path, but it must be valid. For instance, it is an error to attempt to create a file whose immediate parent does not exist.
I am wondering if the problem is that the parents of your file don't exist. In this case the folders .myapp and contentImages.

Cordova 3.6.3 File plugin - get local video file on android

What I'd like to do is
get the URI of a video file on the device via cordovas javascript API
set the URI as value of a HTML5 video tag's src attribute.
The second part shouldn’t be a problem.
Concerning the first task, there are a lot of good structured tutorials like Raymond Camden's demonstrating how to get local files through javascript in an cordova environment.
However, with the newest version of cordova, I could not get it to work.
The video file
The video is located either in assets/www/videos/testvid.webm or res/raw/testvid.webm in the built apk file. Both variations did not work.
The javascript
myPath = cordova.file.applicationDirectory; // -> file:///android_asset/
//myPath += "www/videos/testvid.webm";
respectively
myPath = cordova.file.applicationStorageDirectory; // -> file:///data/data/com.example.MyPackage/
//myPath += "raw/testvid.webm";
Then:
window.resolveLocalFileSystemURL(myPath, gotFile, fail);
function gotFile(entry){
if(entry.isDirectory)
alert JSON.stringify(entry.getFile("testvid.webm"));
}
The permissions
In res/xml/config.xml access permissions are added
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
The error is {code:1} -> NOT_FOUND_ERR
What am I doing wrong? How to navigate to the file, or where can one put it to be found?
I figured it out!
There is a bug in the android version of the cordova file plugin.
A workaround is transferring the file(s) from the assets directory of the app itself file:///android_asset/ (cordova.file.applicationDirectory) to a working directory on the phone like file:///data/data/com.example.MyPackage/files (cordova.file.dataDirectory). Then set the video's source URL to this new file.
XMLHttpRequest as well as FileTransfer will do the trick.
var myFilename = "testvid.webm";
var myUrl = cordova.file.applicationDirectory + "www/videos/" + myFilename;
var fileTransfer = new FileTransfer();
var filePath = cordova.file.dataDirectory + myFilename;
fileTransfer.download(encodeURI(myUrl), filePath, (function(entry) {
/*
res = "download complete:\n"
res += "fullPath: " + entry.fullPath + "\n"
res += "localURL: " + entry.localURL + "\n"
alert(res += "nativeURL: " + entry.nativeURL + "\n")
*/
var vid = document.getElementById("someID");
vid.src = entry.nativeURL;
vid.loop = true;
}), (function(error) {
alert("Video download error: source " + error.source);
alert("Video download error: target " + error.target);
}), true, {
headers: {
Authorization: "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
});

Audio shows 'Invalid source' when linking to a file on local machine using FileOpenPicker

I'm trying to write a JS Windows app. I have a button on the first page, and the click event handler code is as follows:
function pickSingleAudioFile(args) {
document.getElementById("output").innerText += "\n" + this.id + ": ";
// Create the picker object and set options
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
openPicker.fileTypeFilter.replaceAll([".mp3"]);
// Open the picker for the user to pick a file
openPicker.pickSingleFileAsync().then(function (file) {
if (file) {
// Application now has read/write access to the picked file
WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");
document.getElementById("output").innerText += "You picked " + file.name + " from " + file.path;
// Save the file as an audio tag and load it
var audtag = document.createElement('audio');
audtag.setAttribute("id", "audtag");
audtag.setAttribute("controls", "true");
audtag.setAttribute("msAudioCategory", "backgroundcapablemedia");
audtag.setAttribute("src", "\"" + file.path + "\"");
document.getElementById("output").appendChild(audtag);
audtag.load();
} else {
// The picker was dismissed with no selected file
WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
}
});
}
The path is something like "D:\Songs\song1.mp3" or "\network-share\My Music\song name.mp3" I get the "Invalid Source" error when trying to load the file.
At first glance, this:
audtag.setAttribute("src", "\"" + file.path + "\"");
should instead be this:
audtag.setAttribute("src", file.path);
It's not clear why you are adding the backslashes. However, depending on what you are doing and based on samples I've seen, you'd be better off doing something like this:
var fileLocation = window.URL.createObjectURL(file, { oneTimeOnly: true });
audtag.setAttribute("src", fileLocation);
You might check out the "Playback Manager msAudioCategory Sample" from the Windows Dev Center for more ideas.

Form fill and capture fail sometimes using CasperJS

I want to fill the form and take capture of the generated page. So I wrote a CasperJS (This is my first time to use CasperJS) to archive to goal. I read the CasperJS API document but still not sure how to fix the problem.
Below is my code:
var casper = require('casper').create();
var filename = casper.cli.get(0);
var myear = casper.cli.get(1);
var mmon = casper.cli.get(2);
var stk_no = casper.cli.get(3);
casper.start('http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php', function() {
this.fill("form[name='date_form']", {
'myear' : myear,
'mmon' : mmon,
'STK_NO': stk_no
},true);
});
casper.then(function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
casper.run();
My command is like
casperjs test.js picture.png 2013 12 8271
Sometimes no picture file will be generated and it turns out to be failed:
Saved screenshot of http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAY.php to picture.png
Sometimes a picture file will be generated and it turns out to be successful:
Saved screenshot of http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/genpage/Report201312/201312_F3_1_8_8271.php?STK_NO=8271&myear=2013&mmon=12 to picture.png
Why does sometime it work and give the capture but sometimes fail? Why the return value of this.getCurrentUrl() could differ?
When the current URL is http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAY.php, means you are blocked in the start page and waiting for the redirect, Change your
casper.then(function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
to:
casper.waitForUrl(/Report/, function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
/Report/ means "Report" in your current URL, so your are at the page data queried.

Categories