navigator.globalization.getLocaleName phonegap globalization - angularjs

I am building an angularjs/phonegap app. using navigator.globalization.getLocaleName always returns 'en_GB' even though I am in Australia (and all devices where purchased in Australia).
navigator.globalization.getLocaleName(
function (locale) {
alert('locale: ' + locale.value + '\n');
console.log(locale);
},
function () {
alert('Error getting locale\n');
}
);
I have tried a few android devices and all are the same. I have read that this setting is build into the firmware on the device. is this correct or am I missing something from my settings?

so I added the phonegap geolocation plugin and this is now working for me. I couldn't find any documentation on this!

Related

cn1PostMessage is undefined on Android. PostMessage is not working

I created a webview (BrowserComponent) and added a listener:
BComp.addWebEventListener(BrowserComponent.onMessage, e->{
Display.getInstance().callSerially(()->{
Dialog.show("Message", (String)e.getSource(), "OK", null);
});
});
Then, in the JavaScript of the embedded website, I called cn1PostMessage and postMesage. This works well in the simulator! But when building the application, on Android, it does nothing (cn1PostMessage is undefined and postMessage is not received by the main program).
var msg = "test";
if(window.cn1PostMessage) {
window.cn1PostMessage(msg);
} else {
window.parent.postMessage(msg, '*');
// Tried: window.postMessage(msg, '*');
// Tried: window.top.postMessage(msg, '*');
}
What can I do?
Thanks!
I just tried building the BrowserComponentPostMessageSample, and it seemed to work fine on my Galaxy S8, Android 8.
If you're finding that window.cn1PostMessage is undefined, then either there was a javascript error in page load that prevented that callback from being installed, or your code is running before the CodenameOne initialization code has run.
I have just added support for the "android.webContentsDebuggingEnabled" display property, which will make the app's web views debuggable using Chrome's remote development tools. This will make it easier for your to track down such issues. See usage example:
Display.getInstance().setProperty("android.webContentsDebuggingEnabled", "true");
This will be available in Friday's update (Dec. 6/19).
In the mean time, I recommend starting with the BrowserComponentPostMessageSample and modifying it to suit your needs from there.
Alternatively, if you can post a test case to demonstrate the issue, I can look at it.

Web bluetooth: How do I detect iBeacon?

I have been fiddling with the new web bluetooth functionality. I have one of these estimote beacons: http://developer.estimote.com/
I know the uuid for my beacon. Here is the code I am using(it is an angular app, hence $scope, $window):
$scope.runBT = runBT;
function runBT() {
let mobile = getMobileOperatingSystem();
if (mobile === 'Android' || mobile === 'iOS') {
$window.navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: ['b9407f30-f5f8-466e-aff9-25556b57fe6d']
})
.then(device => {
console.log('FOUND DEVICE: ', device);
device.watchAdvertisements();
device.addEventListener('advertisementreceived', interpretIBeacon);
})
.catch(error => { console.log(error); });
}
}
function interpretIBeacon(event) {
var rssi = event.rssi;
var appleData = event.manufacturerData.get(0x004C);
if (appleData.byteLength != 23 ||
appleData.getUint16(0, false) !== 0x0215) {
console.log({isBeacon: false});
}
var uuidArray = new Uint8Array(appleData.buffer, 2, 16);
var major = appleData.getUint16(18, false);
var minor = appleData.getUint16(20, false);
var txPowerAt1m = -appleData.getInt8(22);
console.log({
isBeacon: true,
uuidArray,
major,
minor,
pathLossVs1m: txPowerAt1m - rssi});
}
Sadly the watchAdvertisements method is not implemented yet. You may want to check the Implementation Status page at https://github.com/WebBluetoothCG/web-bluetooth/blob/master/implementation-status.md to know when this method will be supported in Chrome and other browsers.
It's unclear what the problem is, but here are a few tips:
Understand that the web bluetooth APIs are a proposed set of standards under active development, and support is limited to certain builds of Google Chrome, and as a shim for the Noble.js bluetooth central module. If you are using Angular, you need to use the latter shim to make it work, which perhaps you already are. You can read more here: https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web
If you are getting as far as the interpretIBeacon function, then it's just a matter of parsing the bytes out, which you seem well on your way to doing. You can see more about the byte layout of the beacon in my answer here: https://stackoverflow.com/a/19040616/1461050
You don't want to filter for the beacon UUID as a service, so you need to remove optionalServices: ['b9407f30-f5f8-466e-aff9-25556b57fe6d']. A beacon ProximityUUID is not the same as a GATT ServiceUUID even though they superficially have the same format. A beacon bluetooth advertisement of the type you are looking for a manufacturer advertisement and not a *GATT service** advertisement. The two advertisement types are different, but the APIs shown above should return results from both types.

AngularJS and BrightCove Media API

I am working on integrating BrightCove into an Ionic App (allows HTML and JS/Angular to run as a native app on mobile devices).
The app will play videos and allow user's to download the video to save the user's device, I can get the app to play the video but am having issues getting the
Media API to run the 'find_video_by_id' call.
So I have a download button which triggers the following function
_this.downloadBrightcoveVideo = () => {
let searchParams = {}
BCMAPI.token = 'xxxx..'
BCMAPI.callback = 'useDownloadLink'
BCMAPI.command = 'find_video_by_id'
searchParams.video_id = 1234567890
searchParams.media_delivery = 'HTTP'
searchParams.video_fields = 'FLVURL'
BCMAPI.find (BCMAPI.command, searchParams)
}
where token and video_id are set to my video and URL Access token.
I have tried setting the useDownloadLink function as below
let useDownloadLink = function () { console.log ("I'm Alive") }
or
function useDownloadLink () { console.log ("I'm Alive") }
or
_this. useDownloadLink = () => { console.log ("I'm Alive") }
Every time I run the code I get the error below, even though I have useDownloadLink above the download function
Uncaught ReferenceError: useDownloadLink is not defined
I have tried several variations now and nothing is working, any solution would be gratefully received.
Thanks in advance,
Áine
So after a bit of Google-ing came to the conclusion it was better to use BrightCove's CMS Api to achieve the results I wanted, once going through the api it was actually pretty simple..
Hope that helps someone else :D
Happy Coding!

Cordova Windows Phone 8 Play Local File Sound

How can I play a local mp3 file in the www folder?
Example: I need to play the following file : 'www/audio/button.mp3'. So:
1) I install the Cordova media and the media capture plugin.
2) I add the following code in the DeviceReady event handler :
var media=null;
function onDeviceReady()
{
alert("ready");
addSoundEffects();
}
function addSoundEffects(){
var soundUrl=getMediaUrl("/audio/button.mp3");
media=new Media(soundUrl,mediaLoaded,mediaError);
alert('after');
}
function getMediaUrl(s){
if(device.platform.toLowerCase() === "android") return "/android_asset/www" + s;
return 'www'+s;
}
function mediaLoaded(){
alert('Media loaded correctly');
}
function mediaError(e) {
alert('Media Error');
alert(JSON.stringify(e));
}
3) I run the application on my windows phone device, but it just stopped on the media=new Media(soundUrl,mediaLoaded,mediaError); row. I can see the "after" alert, but the function above doesn't call mediaLoaded neither mediaError, i don't know what to do.
NOTE: I think that the path is not the problem, otherwise it should just call the mediaError callback. I notice that the 'Media' variable is undefined, i don't know if can help.
Thanks for answer, i have been working on this from 3 hours and i can't find anything on google!
try to add '/' before www. It works in my apps

How to fetch user's mobile number in phone gap App

Is there any way to fetch user's mobile number in phone gap app?
There is no way you could directly use it in phonegap first you should find how to do this in each platform(ios,android,..) then with phonegap-plugins you could integrate them in your app easily. be aware that this solution is platform base
tip: what you are doing is against apple legal Agreement and you will rejected from apple app store if you use that in your application .
https://github.com/macdonst/TelephoneNumberPlugin
I havnt tried it but i think it works for android devices
Try this document
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-contacts/index.html#navigatorcontactspickcontact
This code 100% work fine
function onDeviceReady() {
// Now safe to use device APIs
window.addEventListener("batterystatus", onBatteryStatus, false);
$("#contact").click(function () {
navigator.contacts.pickContact(function (contact) {
console.log('The following contact has been selected:' + JSON.stringify(contact));
$("#contact_details").html('The following contact has been selected:' + JSON.stringify(contact.phoneNumbers));
}, function (err) {
console.log('Error: ' + err);
});
});
}

Resources