I developing an app for iOS and Android using PhoneGap 3.4.0 from the command line interface, and want to make use of the BarcodeScanner plugin. The problem is that the scanner does not actually do anything when called by my app. The camera does not come up. By using console.log with Safari developer tools, I can tell that the scan function does exist and is getting called... it just isn't doing anything.
I installed the scanner plugin like this:
phonegap plugin add https://github.com/wildabeast/BarcodeScanner
In the index.html, included the javascripts like this:
<script src="phonegap.js"></script>
<script src="barcodescanner.js"></script>
In config.xml, added this:
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
When I set scanner variable like this it logs that there is a BarcodeScanner, and it does have a function scan, but then when I call the function scan nothing happens. (the camera does not open).
var scanner = cordova.plugins.barcodeScanner;
console.log(scanner) // => BarcodeScanner
This is how I'm calling the scan function:
scanner.scan( function (result) {
... my code here...
} );
Any ideas? I'd really appreciate any help or pointers in how to get the barcodeScanner to work with PhoneGap.
I´m having the exact same problem.
After I updated my App to support arm64 (iPad Air), I ran into this issue.
A work-a-round:
Push the hardware On/Off button.
Turn on the device again.
Try starting the barcodeScanner.
This worked for me - but the App will not leave my desk before the issue has been fixed properly.
The issue now exists on all of my devices (iPad Mini, iPhone 4S, iPad Air).
The problem was that the version from wildabeast was not compatible with PhoneGap >= 3.2.0.
Use this branch instead: https://github.com/phonegap-build/BarcodeScanner
Install with
phonegap local plugin add https://github.com/phonegap-build/BarcodeScanner
To get it to work, I had to create a brand new app, copy the www folder over, and then install the plugin.
Related
I am trying to test cookie in device, so i build a simple application.
I have tested it on emulator and works fine.
but when i test it in apps testing server, and in device, All the Intel xdk function doesnt work (I just want test cookie),
I have put script <script>src="intelxdk.js"</script> in index.html.
But it doesnt work also, i have searched here,
intel-xdk html5 platform android aplication working properly in emulator but not working properly in device , so i include the <script src="xhr.js"></script> but it doesnt work also
My code is:
(Sorry, im just new here and cant post image if post under 10. Here the image)
http://helpmedong.esy.es/
The alert is still : Intel is not defined..
thx before..
ive found the problem.
I click "Project" button =>
then click +plugin tab =>
featured and custome cordova plugins =>
check the cache option.
Thx everyone.
And then put the coding in deviceready.
About my comment above and with cheyong help, I go to this way...
If you begin with project withou Cordova you click second option
But, in this way haven't plugins choice:
Than upgrade...
Note the option "plugins"
I'm testing my app on a Galaxy Tab 2.
I have a button which looks like this in the code:
<button class='msdsBtn' onclick='launchGoogle();'>msds</button>
// test function
function launchGoogle(){
alertw("launch google");
intel.xdk.device.launchExternal("http://www.google.com");
}
// wrapper for xdk alert
function alertw(str){
intel.xdk.notification.alert(str);
}
the button doesn't do anything. No errors, no opening of Google, no alert box... nothing.
These buttons are dynamically created on the page.
Am I missing something? I should note that it all works in the emulator.
Do you have the proper plugin ("Notification", I believe, in this case) checked in your project settings?
I wouldn't spend too much time figuring out how to make this call work, as Intel is deprecating the XDK APIs that are redundant with Cordova APIs.
Instead, try switching out your notification calls with the equivelent Cordova method. It should look something like this:
navigator.notification.alert(message, alertCallback, [title], [buttonName])
And again, make sure you have the right plugin configured in your project settings ("Dialogs"). Your project settings can be accessed through the XDK IDE by clicking "Projects" in the upper left corner.
Here is the full documentation for the Cordova dialogs API:
https://github.com/apache/cordova-plugin-dialogs/blob/master/doc/index.md
EDIT: And as Ian says above, you can of course debug your app as it runs on a device through the Debug tab for Android, and with WEINRE on other platforms.
I am using PhoneGap Build to wrap an AngularJS project as a mobile app, it uses InAppBrowser to open Facebook/Twitter OAuth page.
My configuration:
Angular 1.0.8
PhoneGap 3.1.0 on PhoneGap Build
InAppBrowser 0.2.3
Tested with hydration enabled and disabled, same result
Here is the code snippet I used:
// This part code is called from click handler of a button,
// this is the only place that used the PhoneGap API.
var ipwin; // Used in somewhere else
document.addEventListener("deviceready", function() {
ipwin = $window.open("some url", "_blank");
$(ipwin).on("loadstop", function(e) {
var url = e.originalEvent.url;
console.log("loadstop: " + url);
// snipped
});
// Below are testing code added while debugging
var test = function() {
console.log("setTimeout test");
};
setTimeout(test, 2000);
test();
}, false);
This works fine on Android 4.0, however on Android 2.3 the loadstop event does not fire. I also tried loadstart and loaderror, none of them fires. More strangely, setTimeout test only appears in console output once instead of twice. Is there any problem in my code?
After some refactor and changes to the app, the problem is mysteriously gone. Not entirely sure but I think it is because some other scripts in the page conflicted with cordova.js.
I was experiencing similar problems with both PhoneGap 3.0 and 3.1 on Android, reverting to PhoneGap 2.9 made these InAppBrowser events fire again.
It looks like to be a problem with the last phonegap/cordova version 3.1.0.
https://groups.google.com/forum/#!topic/phonegap/e5_5unC2fYs
Try an older version.
this issue happened to me and I did these steps to solve it:
Upgrade your Phonegap version to 3.1
Create a new project
Add your platforms then your plugins
Copy your code again back to www
this should solve your problem
Background
I'm attempting to upgrade an iOS app built on Cordova 2.0 to version 2.7.
It's basically a welcome screen that points to a remote search engine (please withhold comments about app validity and likely approval, as we're past that), and we were using the ChildBrowser plugin to enable opening links in a sub browser so as not to trap the user in the Cordova webview.
Cordova 2.7 has a feature called InAppBrowser I am hoping to use instead of ChildBrowser. InAppBrowser does essentially the same thing, aside from missing a button to open in Safari.
Problem
The existing app's remote webpages include the Cordova JS (as well as that for the ChildBrowser plugin) and it works fine for opening links in the sub browser.
My test Cordova 2.7 app doesn't seem to load the Cordova JS correctly when it's being loaded from a remote web page.
I tried using this exact same HTML on the embedded start page and a remote start page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://mydomain.com/mobile/cordova-2.7.0.js"></script>
</head>
<body>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("Ready!!");
}
</script>
</body>
</html>
To test this as the embedded start page, I put this line in config.xml:
<content src="index.html" />
When I run the app, I promptly get the "Ready!" alert.
To test this as the remote start page (I'm aiming to link to the remote page in the final app, I am just using it as the start page for testing. The result is the same if I link from the embedded page.), I put this line in config.xml:
<content src="http://mydomain.com/mobile/index.php" />
When I run the app, I just get the blank screen and no alert.
Further, in cordova-2.7.0.js L. 6255, I changed
console.log('deviceready has not fired after 5 seconds.');
to
alert('deviceready has not fired after 5 seconds.');
With that change, running the app using the remote start page causes the blank page, and then after five seconds, I get the alert "deviceready has not fired after 5 seconds.". So this tells me Cordova JS is not starting correctly. Needless to say, I can't get InAppBrowser to launch links in the sub browser on the remote site, but I can get it working just fine on the embedded start page.
Anyone have any ideas of where to go from here? This is a pretty simplistic example, so I'm assuming this is a Cordova settings problem or a change in the functionality. I appreciate any thoughts, thanks!
Yes, something broke in 2.7 - related to our cordova-cli work. See: https://issues.apache.org/jira/browse/CB-3029
The fix is to add an empty file called "cordova_plugins.json" in your root folder.
I had a similar problem relating to upgrading to Cordova 2.7. However my problem was all my console.logs stopped firing when running the app. I couldn't figure out why for the life of me this was happening. I thought it was because I upgraded jquery.mobile. That wasn't it. I then thought it was an .htaccess issue, that wasn't it either. It turns out, it was Cordova 2.7 that was causing this problem.
I did try adding the .json file on my server, that did not fix the issue.
The fix was going into the 2.7 source and commenting out the following code:
/*comment out this as it is breaking console.logs
var xhr = new context.XMLHttpRequest();
xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
var obj = this.responseText && JSON.parse(this.responseText);
if (obj && obj instanceof Array && obj.length > 0) {
handlePluginsObject(obj);
} else {
finishPluginLoading();
}
};
xhr.onerror = function() {
finishPluginLoading();
};
xhr.open('GET', 'cordova_plugins.json', true); // Async
xhr.send();
*/
Replace entire block with a call to the following function:
finishPluginLoading();
My logs are now working again. Only took me 3 days scratching my head.
Hope this helps someone with a similar problem.
If you embed Cordova in the external web page, there will be no way to open the InAppBrowser from within your hybrid app, so Cordova will not be able to load. This is because the InAppBrowser requires Cordova to be fully loaded and initialized before it can be used to fetch a remote page. You need to use your HTML page that you have, with the <script type="text/javascript" src="http://mydomain.com/mobile/cordova-2.7.0.js"></script> as the main entry point for your app. Then you can use the InAppBrowser to open up your remote page. (You could probably do this in the onDeviceReady(), not sure if it would "flash" the page first though.) I don't think the remote page should have any Cordova code in it at all. I'm not sure if it would be possible to even interact with Cordova from the remote page due to the Same Origin Policy (probably you could use features of the InAppBrowser to inject "bridge" code though to get around this.)
As Shazron mentioned the problem is the issue with the file"cordova_plugins.json".
To solve the problem not changing the code you can create the "cordova_plugins.json" file in the root folder and insert a content between quotation marks inside this file.
Mine for example has the following content:
"Just a dummy file required since Cordova 2.6.0"
create a file cordova_plugins.json that contains {}. then go to cordova-2.7.0.js and comment this line require('cordova/channel').onNativeReady.fire(); then when development done, add it back
Like me if you are using Cordova 5.1.1 and want to access native functionality after redirect then copy cordova.js, cordova_plugins.js and plugins folder which is at \platforms\platform_name\assets\www\ and put them on server, finally reference cordova.js inside your html. After every plugin add make sure to update these files and folder.
I have used the system notification plugin from the github(https://github.com/saileshmittal/phonegap-system-notification-plugin) for android phonegap.I have used this code in my index.html
My code is:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var not_title = 'Message';
var not_text = 'Zou dit werken?';
var not_tText = 'Message';
navigator.systemNotification.onBackground();
navigator.systemNotification.onForeground();
navigator.systemNotification.createStatusBarNotification(not_title, not_text, not_tText);
}
I got the notification icon in both foreground and background.But is it possible to run the whole application to run in the background when the button is clicked in the application and call my wcf services continuously.Also i need to get the alert even when running in the background.how to do that?
navigator.systemNotification.onBackground():this line run the application in background or not other wise it only for showing the notification after closing the application.
please guide me,thanks in advance.
I made an Android application with PhoneGap and when I press the home button, my application stays in background (with my last test it stays more than 1 hour). But when I launch other App the Android OS kills my application.
To enable this behaviour you need to add the android permission:
<uses-permission android:name="android.permission.WAKE_LOCK" /> to your manifest
and you also need to add:
<preference name="exit-on-suspend" value="false" /> to your config.xml in folder res/xml
I hope this post can you help you :)
According to the phonegap documentation you cannot run the apps in the background, the js cannot continue to run. The reason notifications are able to work is because they are using the native system to send the notifications.
In order to make processes run in the background you will need to create a plugin that uses the native os.