If you need to prevent the sleeping mode here is a plugin that does this..
Install it:
cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
or
phonegap plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git
than to use it this is the code; to prevent sleep mode use:
window.plugins.insomnia.keepAwake()
instead to re-allow the sleeping mode again use:
window.plugins.insomnia.allowSleepAgain()
Please refer here to full documentation.....
Bye..
Showing posts with label cordova. Show all posts
Showing posts with label cordova. Show all posts
Friday, April 22, 2016
Tuesday, April 5, 2016
Cordova/PhoneGap force the calling to the virtual keyboard - how to
I've spent some days to search a solution to an issue I have when a input text in my ui needs to show the android virtual keyboard.
The only way I found, is to add a plugin to my cordova-phonegap project via command line interface.
First, ensure you have cordova.js included/imported in your html page.
Move into the project directory and type:
cordova plugin add ionic-plugin-keyboard
the in your code(javascript) when you need call this:
cordova.plugins.Keyboard.show();
...and the virtual keyboard show up.
Note that during development if you are testing your app in the browser, probably you'll be notified by this error:
"Cannot read property 'Keyboard' of undefined"
It's depends by the cordova.js that you have included into the page, but it is imported only when application is built for the devices.
So you will really see it in the device or in device emulator.
It's all.
I try it only in Android. Please notify me(also with a simple comment) if it correctly works on other platforms.
Here you can find some documentation.
Bye...
The only way I found, is to add a plugin to my cordova-phonegap project via command line interface.
First, ensure you have cordova.js included/imported in your html page.
Move into the project directory and type:
cordova plugin add ionic-plugin-keyboard
the in your code(javascript) when you need call this:
cordova.plugins.Keyboard.show();
...and the virtual keyboard show up.
Note that during development if you are testing your app in the browser, probably you'll be notified by this error:
"Cannot read property 'Keyboard' of undefined"
It's depends by the cordova.js that you have included into the page, but it is imported only when application is built for the devices.
So you will really see it in the device or in device emulator.
It's all.
I try it only in Android. Please notify me(also with a simple comment) if it correctly works on other platforms.
Here you can find some documentation.
Bye...
Thursday, February 26, 2015
Cordova/PhoneGap: prevent screen rotation
Fix the screen side of your app, preventing screen rotation.
Edit the config.xml file, the orientation preference tag in one of these ways:
Bye...
Edit the config.xml file, the orientation preference tag in one of these ways:
<preference name="orientation" value="portrait" />
<preference name="orientation" value="landscape" />
Bye...
Thursday, January 29, 2015
PhoneGap plugins: file transfer - download
file-transfer plugin needed.
Install it with this:
phonegap plugin add org.apache.cordova.file-transfer
Here is my example.html(within javascript code).
This example provides a file download(pay attention to change the value of file url to download):
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Transfer - download - Example Page</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// !! Assumes variable fileURL contains a valid URL to a path on the device,
// for example, cdvfile://localhost/persistent/path/to/downloads/
function startDownload () {
alert ("invoked startDownload function...") ;
var fileTransfer = new FileTransfer();
var downloadUrl = encodeURI("http://www.yoursite.com/file_to_download.txt");
var relativeFilePath = "./papa-francesco.sqlite"; // using an absolute path also does not work
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var fileTransfer = new FileTransfer();
fileTransfer.download(
downloadUrl,
// The correct path!
fileSystem.root.toURL() + '/' + relativeFilePath,
function (entry) {
console.log("Success");
},
function (error) {
console.log("Error during download. Code = " + error.code);
}
);
});
}
</script>
</head>
<body>
<p><button onclick="startDownload()">start download</button></p>
</body>
</html>
Bye...
Install it with this:
phonegap plugin add org.apache.cordova.file-transfer
Here is my example.html(within javascript code).
This example provides a file download(pay attention to change the value of file url to download):
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Transfer - download - Example Page</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// !! Assumes variable fileURL contains a valid URL to a path on the device,
// for example, cdvfile://localhost/persistent/path/to/downloads/
function startDownload () {
alert ("invoked startDownload function...") ;
var fileTransfer = new FileTransfer();
var downloadUrl = encodeURI("http://www.yoursite.com/file_to_download.txt");
var relativeFilePath = "./papa-francesco.sqlite"; // using an absolute path also does not work
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var fileTransfer = new FileTransfer();
fileTransfer.download(
downloadUrl,
// The correct path!
fileSystem.root.toURL() + '/' + relativeFilePath,
function (entry) {
console.log("Success");
},
function (error) {
console.log("Error during download. Code = " + error.code);
}
);
});
}
</script>
</head>
<body>
<p><button onclick="startDownload()">start download</button></p>
</body>
</html>
Bye...
PhoneGap/Cordova: file reading plugin example
file plugin needed.
Install it with this:
phonegap plugin add org.apache.cordova.file
Here is my example.html(within javascript code).
This example provides to read file in locale storage, displaying its contents into a javascript alert:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Read File Example Page</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("writing_test_with_phonegap.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
alert("gotFile invoked with file: " + file.name);
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
alert(evt.target.result);
};
reader.readAsText(file);
}
function fail(evt) {
console.log(evt.target.error.code);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Read File</p>
</body>
</html>
Bye...
Install it with this:
phonegap plugin add org.apache.cordova.file
Here is my example.html(within javascript code).
This example provides to read file in locale storage, displaying its contents into a javascript alert:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Read File Example Page</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("writing_test_with_phonegap.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
alert("gotFile invoked with file: " + file.name);
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
alert(evt.target.result);
};
reader.readAsText(file);
}
function fail(evt) {
console.log(evt.target.error.code);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Read File</p>
</body>
</html>
Bye...
Subscribe to:
Posts (Atom)