I want to get contact list from Android(If user open website in android). I was searching on it little bit. I found two question in stackoverflow similar to this.
Obtain Contacts Permission before Navigating (Cordova)
Listing phone contacts using javascript
Cordova
Here what I tried.
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
};
function onError(contactError) {
alert('onError!');
};
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);
I didn't get any error or alert message in android. When I visit the webpage in PC I got an error
Uncaught ReferenceError: ContactFindOptions is not defined
at contacts.php:17
I think I am having error cause, there's no contact function in PC.
I am so beginner in JS. I think Cordova must be installed in PC, I am not sure of the information also. If I have to than how can I install Cordova? I am using Debian Based Linux Distro. So, I tried
sudo apt-get install cordova
But,
E: Unable to locate package cordova
Are you building a mobile app with Cordova or are you just running your code in a website on Android?
If it’s just a website: you simply can’t do what you want since the browser doesn’t provide an interface to the contact list.
Unlike a Cordova app, which has access to the system APIs, among them the contact list API, JavaScript Code executed in a mobile browser, cannot access such APIs. The browser JS API simply provides no way.
JavaScript code run inside a Cordova/Capacitor mobile app however can Cordova APIs which bridge the mobile’s native API to JavaScript.
Related
We have a web based jquery mobile app that records activity of a user. This app is long standing and in use at the moment, so re-writing the application is not an option unfortunatly.
The problem is that we are trying to get GPS location at certain points using the application.. But as it is running in an instance of chrome, the javascript will not record correctly when the phone is locked, or the chrome is minimised.
So to get around that we are writing an Ionic App with Cordova in order to get the GPS coordinates in the background, regardless of the state of the browser.
Currently, this is working great. The issue however is there are certain events in our javascript that require a specific 'type' associated to our GPS logging.
My question is: How do I actually hook onto this javascript event in CHROME from the GPS background ionic/cordova application.
What we have tried so far:
Finding the chrome localstorage via Ionic/Cordova and reading a value from that on a timer.
The issue with this is we can't find the location of the localstorage/cache.
From this question it says its here:
/data/data/com.android.chrome/cache
but we can't find/access it from our ionic app or file browser on the android
https://android.stackexchange.com/questions/85998/android-google-chrome-browser-cache-location
We have also looked for ways to hook the javascript events to fire something inside the other application but we are having no luck there either..
Apologies for the long post.. Its hard to explain. If you have any suggestions on alternative methods to do this kind of cross-application event firing from Chrome to Ionic/Cordova I would be greatly interested to hear your oppinion.
To fix this I created a 'stack' where I could push an object to an array that would be picked up by the cordova app using executeScript as follows:
In the inappbrowser site:
var stackName = stackN1
function addEventToStack(numid, type) {
var stackRow = { 'numb': numid, 'type': type};
var stack = localGet(stackName); //localstorage
if (!stack)
stack = StackInit();
stack.push(stackRow);
localStore(stackName, stack);
console.log('Added to stack ', stack);
return 'Row Added';
}
In the cordova application:
ref.executeScript(
{
code: 'localStorage.getItem("stackN1")'
},
function(rdObj) {
//Iterate and use rdObj here
}
I have been trying to create an Ionic Google login popup with Firebase. However, when the user tries to press the login button, the function is called producing a popup that is surprisingly completely blank.
$scope.login = function()
{
baseRef.authWithOAuthPopup("google", function(error, authData)
{
if (error)
{
alert('Hello');
}
else
{
$scope.auth = authData.google;
$scope.user.set("name", $scope.auth.displayName);
$scope.user.set("image", $scope.auth.profileImageURL)
$scope.user.save();
}
});
};
All my permissions in Firebase and Google have been properly set as well as those in the config file. Does anyone have any idea how I can possibly fix this issue to allow a functional popup to spawn?
I had quite a problem with this also.
It appears to work well with iOS, but no luck with android.
By using the command 'ionic state save' followed by 'ionic state restore' ionic readded the android and iOS platforms. It also added cordova-plugin-inappbrowser, cordova-plugin-whitelist (plugins) to the package.json file.
Next, I created an android build using 'ionic package build android' and send it to my OnePlus 2 using TestFairy.
Finally works, for both google and facebook.
In summary once the package.json file included the relevant plugins, I was able to create an APK file that worked with the firebase $authWithOAuthPopup.
(with these amendments, iOS still seems to work fine)
Tried both of the following methods so that ppl can click a link in my app and be taken to the app store to review/rate:
Rate our App
and when this linked is tapped on, nothing happens and i get the following console message:
Failed to load webpage with error: The URL can’t be shown
Also tried a window.open:
$(document).hammer().on('tap', self.frameSelector + ' .rate-us-action', function(){
window.open('itms-apps://itunes.apple.com/app/id111111111');
});
and when tapping attempting this method nothing happens and i get the following console message:
handle url: itms-apps://itunes.apple.com/app/id1111111
How do i get my phonegap app to properly open a link to the appstore???
Try this format for <> has to be replaced with the appropriate info:
http://itunes.apple.com/app/<APP_NAME>/id<APP_ID>?mt=8
I've used the following link format for Cordova/PhoneGap apps since Cordova 2.2 & iOS 5:
itms-apps://itunes.com/apps/appname
Simply replace appname with your app's name.
Rate our App
You can also open the App Store and display a page of apps by your company with the same format:
itms-apps://itunes.com/apps/companyname
In a link:
More Apps By Us
This works today on iOS 8.1.1 without the Cordova inappbrowser plugin.
I'm attempting to create a custom home page for Sharepoint 2013 which will operate similarly to the promoted links app - displaying all the apps installed by a user in a metro style interface.
The promoted links app works great, but my issue is that we want users to be able to install their own apps from the app catalog without having to edit the promoted links list to display it on the home page.
Is it possible to grab the url's / names of all the apps installed by a user from a web part?
The solution provided by Vadim is what I attempted first, but I found it did not return the apps installed. After a few trial and errors I discovered it was because I needed to look at the root web rather than the web where the app was installed.
So, in summary, my version is pretty much identical except for how the web is set:
web = ctx.get_site().get_rootWeb();
Use SP.AppCatalog.getAppInstances Method to retrieve AppInstance objects installed on an instance of SharePoint:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var appInstances = SP.AppCatalog.getAppInstances(ctx, web);
ctx.load(appInstances);
ctx.executeQueryAsync(
function () {
//iterate apps
for(var i = 0; i < appInstances.get_count();i++) {
//...
}
} ,
function (sender, args) {
console.log(JSON.stringify(args));
});
here's my situation. I have a html +css + jquery well working project that I want to adapt in titanium. This project has geolocation + fb api call.
I want to adapt my project into a titanium html5 project. What I found is that I can call titanium api only through addEventListener and fireEvent functions (of course only if I use webviews).
it' my first titanium project I work with that needs geolocation and facebook api.
actually, I started to modify the previous project by adding addEventlistener into the app.js file and fireEvents into the javascript files of the previous project ( included in the first project in the html files) in the parts that need the titanium api calls (I can't call titanium api outside of app.js).
the problem is that I need some values (objects) to be returned back.
to better understand what I'm doing, here's the sequence of the events.
TITANIUM PROJECT
(app.js)
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'index.html'
});
Ti.App.addEventListener('geolocation',function(){
//some titanium api call
lat = x;lon=y;
Ti.App.fireEvent('geolocation_back',{latitude:lat,longitude:lon});
});
win.add(webview);
win.open();
HTML + CSS + JS PROJECT
(imported file into index.html, not imported into app.js)
Ti.App.fireEvent('geolocation');
var my_lat ;
var my_lon ;
Ti.App.addEventListener('geolocation_back',function(d){
my_lat = d.latitude;
my_lon = d.longitude;
//do other stuff with my_lat and my_lon
});
I hope you understand what I'm doing.
my questions are:
1) is what I am doing the correct way to work with titanium and html code?
2) is there anyother way to call titanium api within html code and return variables/objects back?
EDIT
this code works only on iOS and android but not on web browser. it seems that the built in server (Titanium studio or Android web browser emulator) doesn't load the Ti.* or Titanium.* objects. is there anyway to make it works on web browser?
I see the web mobile compiler creates all the titanium API in subfolders
there is titanium.js and TI/* folder. can anyone explains me why the console says me Ti is not defined?
as I said here
I found a solution!
simply add to all of your html pages the simple script below
var Ti = window.parent.Ti
have fun!