detecting if the current code is running as an app or as web page - ionic-framework

I'm developing an hybrid application using ionic.
Most of the features would work on mobile web browser. So the final product can be used from an http address as well. But there are certain code segments/features ( such as vibration, background alerts ) which will obviously be for the app version. And those features will only be available on the app version.
What's a good/recommended way to detect the current situation in the code base so that I can do logic such as if (isRunningAsApp) {do this} else {do that}*?
would it be just checking window.location.href and if you get something that starts wiih http:, then it is a mobile app, otherwise it is an app?

This is from Ionic's documentation
angular.module('PlatformApp', ['ionic']).controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});

Related

How do i make flutter application that open another app within it and not webview

I have tried to make flutter app in which within it I have a list of another application. I want on tap of any app within a list to open that app, like the code below. How to do it in flutter ?
openExternalApp : function(packageName) {
try {
var KonyMain = java.import("com.konylabs.android.KonyMain");
var context = KonyMain.getAppContext();
var pm = KonyMain.getAppContext().getPackageManager();
var intent = pm.getLaunchIntentForPackage(packageName);
if(intent !== null && intent!== undefined){
context.startActivity(intent);
}
else {
var url = "https://play.google.com/store/apps/details?id="+packageName;
kony.application.openURL(url);
}
} catch(e) {
kony.print("error opening app external: "+e)
}
}
If i understood correctly you want to do something like kindle which allows the user to open a book (in this case an app) directly from your app.
That being the case, maybe this package can help you https://pub.dev/packages/device_apps
to check for installed apps List<Application> apps = await DeviceApps.getInstalledApplications();
and to launch the app DeviceApps.openApp('package.name');
This package currently only supports android.

Is it possible to get location from Messenger Webview

I'm trying to get user location inside a Facebook Messenger Chat-Extension.
I open the webview and ask as usual :
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
};
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
};
navigator.geolocation.getCurrentPosition(success, error, options);
I'm getting this issue : ERROR(1): User denied Geolocation.Is there a way to get user location through Chat Extension Webview ? Thank you
geolocation should work fine on most iOS devices, but will fail on most (if not all) Android devices. That said there is no cross-platform solution for retrieving a user's geo location properly within a webview or Chat extension.

How to use SQLite database in Cordova for iOS?

Same code works for Android but it doesn't work on iOS device. I want to create an SQLite database in cross platform using SQLite plugin. it working in safari browser. but doesn't work in device.
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
receivedEvent: function(id) {
var shortName = 'WebSqlDB';
var version = '1.0';
var displayName = 'WebSqlDB';
var maxSize = 65535;
myDB=openDatabase(shortName, version, displayName,maxSize);
}
Please help me.

How to use POST method in Appcelerator Titanium for iPhone?

I have used the POST method in Titanium for Android app and it is working fine. But in iPhoen Simulator it shows a blank array in the server side to be posted.
var req = Titanium.Network.createHTTPClient({
timeout : 15000
});
req.open("POST", url);
req.onload = function(e) {
//YOUR CODE HERE
}
req.onerror = function(e) {
//YOUR CODE HERE
}
req.send(params);
If, server requires json format of data than you can use req.send(JSON.stringify(params)) otherwise you can send it simply.

Uploading files with PhoneGap + iPhone

I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn't provide controls to upload files.
Does PhoneGap provide any mechanisms that allow users to upload files? (images / video, in the case of the iPhone)
I know Titanium allows users to do this, but it's a different animal with its compiled Javascript and proprietary APIs. Thanks for your advice/input.
I believe you might be able to read the files using the PhoneGap API and the upload them using and AJAX post if the server application supported it.
The other option is to write a custom module/Plugin in PhoneGap that could specific to your needs.
Here are some Example Plugins
You can do an xmlhttprequest to the file on a local drive.
I'm not 100% sure if it will work on the iPhone, but webkit should support it.
function getImageBinaries(url) { //synchronous binary downloader for firefox2
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send("");
if (req.status != 200) {
return "";
}
var t = req.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
ff[z] = scc(t.charCodeAt(z) & 255);
}
var b = ff.join("");
return b;
}
Succes,
Erik