How to exit an application on Windows Phone 8 programmatically - windows-phone-8

I am creating an application in which when i press the cancel button the application should close.
for that I have used " navigator.app.exitApp()" statement as given a solution in stack overflow.
This solution is working in android but it is not working in windows phone 8.
Windows phone is throwing exception that "Unable to get property 'exitApp' of undefined or null reference"
I have written following code for this.
cancelLogin: function () {
var result = DevExpress.ui.dialog.confirm('Do you want to exit ?', 'Confirm Exit');
result.done(function (dialogResult) {
try {
if (dialogResult === true) {
navigator.app.exitApp();
}
}
catch (e) {
DevExpress.ui.dialog.alert(e.message, 'Exception');
}
});
}
this works fine in android but not working in windows phone.
how can I close an application programetically in windows phone 8 ??

The exitApp method is not supported by Cordova APIs for Windows Phone 8. To solve the problem, please execute the following code for the Windows Phone 8 platform:
window.external.Notify("DevExpress.ExitApp");
If you create a Windows Phone application using the DevExtreme wizard, the required code will be automatically generated.
if(device.platform === "win8" && device.phone) {
defaultLayout = "simple";
startupView = "Navigation";
$.each(Application1.config.navigation, function (i, item) { item.root = false; });
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
if(Application1.app.canBack()) {
Application1.app.back();
}
else {
if(window.external) {
window.external.Notify("DevExpress.ExitApp");
}
}
}
Thanks,

Related

Web NFC on Chrome Android

I am trying to explore on web NFC and found a simple sample (https://googlechrome.github.io/samples/web-nfc/). So, I copy the sample code to test it on local:
<html><head>
<title>Web NFC Sample</title>
<script>
// Add a global error event listener early on in the page load, to help ensure that browsers
// which don't support specific functionality still end up displaying a meaningful message.
window.addEventListener('error', function(error) {
if (ChromeSamples && ChromeSamples.setStatus) {
console.error(error);
ChromeSamples.setStatus(error.message + ' (Your browser may not support this feature.)');
error.preventDefault();
}
});
</script>
<link rel="stylesheet" href="Web%20NFC%20Sample_files/main.css">
</head>
<body>
<button id="scanButton">Scan</button>
<button id="writeButton">Write</button>
<script>
var ChromeSamples = {
log: function() {
var line = Array.prototype.slice.call(arguments).map(function(argument) {
return typeof argument === 'string' ? argument : JSON.stringify(argument);
}).join(' ');
document.querySelector('#log').textContent += line + '\n';
},
clearLog: function() {
document.querySelector('#log').textContent = '';
},
setStatus: function(status) {
document.querySelector('#status').textContent = status;
},
setContent: function(newContent) {
var content = document.querySelector('#content');
while(content.hasChildNodes()) {
content.removeChild(content.lastChild);
}
content.appendChild(newContent);
}
};
</script>
<h3>Live Output</h3>
<div id="output" class="output">
<div id="content"></div>
<div id="status">Web NFC is not available.
Please make sure the "Experimental Web Platform features" flag is enabled on Android.</div>
<pre id="log"></pre>
</div>
<script>
if (/Chrome\/(\d+\.\d+.\d+.\d+)/.test(navigator.userAgent)){
// Let's log a warning if the sample is not supposed to execute on this
// version of Chrome.
if (89 > parseInt(RegExp.$1)) {
ChromeSamples.setStatus('Warning! Keep in mind this sample has been tested with Chrome ' + 89 + '.');
}
}
</script>
<script>
log = ChromeSamples.log;
if (!("NDEFReader" in window))
ChromeSamples.setStatus(
"Web NFC is not available.\n" +
'Please make sure the "Experimental Web Platform features" flag is enabled on Android.'
);
</script>
<script>scanButton.addEventListener("click", async () => {
log("User clicked scan button");
try {
const ndef = new NDEFReader();
await ndef.scan();
log("> Scan started");
ndef.addEventListener("readingerror", () => {
log("Argh! Cannot read data from the NFC tag. Try another one?");
});
ndef.addEventListener("reading", ({ message, serialNumber }) => {
log(`> Serial Number: ${serialNumber}`);
log(`> Records: (${message.records.length})`);
});
} catch (error) {
log("Argh! " + error);
}
});
writeButton.addEventListener("click", async () => {
log("User clicked write button");
try {
const ndef = new NDEFReader();
await ndef.write("Hello world!");
log("> Message written");
} catch (error) {
log("Argh! " + error);
}
});
</script>
</body></html>
But when I run it, it shows Web NFC is not available. Please make sure the "Experimental Web Platform features" flag is enabled on Android. on the message. When I click on "scan" button, it shows Argh! ReferenceError: NDEFReader is not defined.
May I know why the sample code work well when it is on https://googlechrome.github.io but can't work when I have it on my local PC? Thank you.
As documented in https://web.dev/nfc/#security-and-permissions, Web NFC is only available in secure browsing contexts. It means you either have to serve your webpage over https:// or localhost such as http://127.0.0.1 or http://localhost.
If you have installed npm, you can use npx http-serve.
If you have installed Python 2, use python -m SimpleHTTPServer
If you have installed Python 3, use python -m http.server

web serial api shows "no compatible devices found" despite being given the vendorId

Windows 8.1, Chrome v91.0.4472.164. I have verified the vendor and product ids against the device manager. The device is a Arduino UNO using the Ch340 driver, it is listed in the device manager under Ports(COM & LPT) as "USB-SERIAL CH340(COM7)"
My code looks like this;
try {
const requestOptions = {
filters: [{
usbVendorId: 0x1A86,
usbProductId: 0x7523
}]
};
const device = await navigator.serial.requestPort(requestOptions);
} catch (e) {
console.log(e);
return;
}
I wonder if usbProductId and usbVendorId are wrong somehow ;(
Can you try this snippet of code which will allow you to get a prompt, select the Arduino UNO device serial port, and check usbProductId and usbVendorId?
const port = await navigator.serial.requestPort();
const { usbProductId, usbVendorId } = port.getInfo();
console.log({ usbProductId, usbVendorId });

Window.ethereum works in Desktop chrome and not in mobile and trustwallet

I have my web3.js detector define as in function below:
const ethEnabled = () => {
if (window.ethereum) {
web3 = new Web3(window.ethereum)
return true
} else if (window.web3) {
web3 = window.web3
return true
}
return false
}
if (!ethEnabled()) {
alert(
'Please install an Ethereum-compatible browser or extension like MetaMask to use this dApp!'
)
}
The problem is that this works in Chrome and Brave browser on desktop but fails on mobile and trustwallet. So the alert message below is triggered.
Please let me know how I should go about this.
Thanks.

framework.realtime.co and phonegap for Android

I'm making a web with framework.realtime.co. It works perfect on web, but when I compile mi web to an app with phonegap, the app works perfect but the connection realtime never works.
On the web version I have msj "Connected" but on the compiled version with phonegap, it just says nothing.
here is the html
<div id="status">
Loading...
</div>
Here is the code js
loadOrtcFactory(IbtRealTimeSJType, function (factory, error) {
if (error != null) {
//////console.log("Factory error: " + error.message);
} else {
client = factory.createClient();
client.setClusterUrl('https://ortc-developers-useast1.realtime.co/server/ssl/2.1');
client.onConnected = function(c) {
document.getElementById('status').innerHTML = "connected";
// send("New hello world");
c.subscribe('channelAlerta', true, elem_received);
}
client.onDisconnected = function() {
document.getElementById('status').innerHTML = "disconnected";
}
client.onReconnecting = function() {
document.getElementById('status').innerHTML = "reconnected ...";
}
client.connect(appkey, token);
}
});
You need to use a websocket PhoneGap plugin. Check the example at
https://github.com/realtime-framework/Messaging/tree/master/PhoneGap

HTML5 getCurrentPosition with Meteor

I'm trying to use the html5 geolocation api with Meteor.
I'm using:
navigator.geolocation.getCurrentPosition(handle_geolocation_query); in my js but it doesn't seem to work - I think it may be related to the timer ( http://docs.meteor.com/#timers ) restrictions Meteor has. Any thoughts?
Thanks #lashleigh it was a loading problem
Here is the code that worked for me (I'm using Modernizr.js to detect geo-location)
if (Meteor.is_client) {
Session.set('loc','?');
//alert(Modernizr.geolocation);
function foundLocation(location) {
console.log(location);
Session.set('loc','lat: '+location.coords.latitude+', lan: '+ location.coords.longitude);
}
function noLocation() {
alert('no location');
}
Template.hello.greeting = function () {
var output;
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
outpout = Session.get('loc');
}
return Session.get('loc');
};
}