Get email account into textfield using cordova - android

Can anyone please show me how to get an email registered to a phone into my cordova application? In my application, there is a registration page which users must register with their emails and instead of them typing it in, I want to use cordova to get the current email on the phone into the textfield of the registration page named "email" and also if possible get the firstname and lastname the user used in registring his email on his phone into a textfield

so you can use the following plugin
[User-Info-Plugin][1]
The way to add would be to use the following command
cordova plugins add https://github.com/xarv/UserInfo-Cordova-Plugin.git
after the adding check your config.xml for proper entries.
Usage:
var success = function(string){
alert(string);
};
var error = function(string){
alert("error");
};
getInfo("email",success,error,"email",[]);`
The getInfo method is the one you should use with action as "email". this should be done after cordova has been loaded i.e. inside onDeviceReady after deviceready has been fired. document.addEventListener('deviceready', onDeviceReady, false);
Also in your manifest you would have to add
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
as a permission.
Hope this helps.

Related

Launching Ionic app using web URL

Here is my situation:
User request an email of forgot password.
User use their Android/iPhone to open email and tap on the link inside the email
When the link is tapped (clicked), it'll call the Ionic app.
I spend the whole morning to research and found this solution: using a plugin of Cordova named Custom-URL-scheme.
I also found out a tutorial from sysgears that I need to add this code into my app.js file:
.run(['$state', '$window',
function($state, $window) {
$window.addEventListener('LaunchUrl', function(event) {
// gets page name from url
var page =/.*:[/]{2}([^?]*)[?]?(.*)/.exec(event.detail.url)[1];
// redirects to page specified in url
$state.go('tab.'+ page, {});
});
}
]);
function handleOpenURL(url) {
setTimeout( function() {
var event = new CustomEvent('LaunchUrl', {detail: {'url': url}});
window.dispatchEvent(event);
}, 0);
}
I've done everything, however it does not work. I tried to type my URL_SCHEME (http://myapp://) into the Chrome browser in Android phone but Chrome just display an error message:
This webpage is not available. ERR_NAME_NOT_RESOLVED.
Please help me. Thanks.
Try to remove the "http://" from your sheme, href and browser
If still not working, can you precise your cordova version, and the plugin version you use. Did you install the plugin with the sheme in --variable URL_SCHEME=myapp
Also, note its "SHEME", not SHEMA

Ionic push not working - user not registered

I just had my first contacts with the ionic framework. I've worked with Phonegap and AngularJS before however, so it was not all that new to me.
I found out that there is this new feature to use Google Cloud Messaging push notifications in Ionic, through the Ionic Push feature (http://blog.ionic.io/announcing-ionic-push-alpha/).
Related lines of code from app.js
angular.module('starter', ['ionic','ionic.service.core', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
// enable push notifications
Ionic.io();
// enable users (http://docs.ionic.io/docs/user-quick-start)
// this will give you a fresh user or the previously saved 'current user'
var user = Ionic.User.current();
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
user.id = Ionic.User.anonymousId();
// user.id = 'your-custom-user-id';
}
console.log('user-id:' + user.id);
//persist the user
user.save();
var push = new Ionic.Push({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
"onRegister": function(data) {
console.log(data.token);
}
});
push.register(function(token) {
console.log("Device token:",token.token);
});
push.addTokenToUser(user);
console.log('token added to user');
});
})
Log from ionic serve
ionic $ 0 361081 log Ionic Core:, init
1 361083 log Ionic Core:, searching for cordova.js
2 361085 log Ionic Core:, attempting to mock plugins
3 361155 log user-id:1cc3d21c-b687-4988-b944-ad07b1a677c8
4 361158 log Ionic Push:, a token must be registered before you can add it to a user.
5 361159 log Ionic Push:, token is not a valid Android or iOS registration id. Cannot save to user.
6 361159 log token added to user
7 361160 log Ionic Push:, register
8 361160 error ReferenceError: PushNotification is not defined, http://localhost:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js, Line: 2
9 361526 log Ionic User:, saved user
Any input is welcome, I am also more than happy to provide more information if needed.
EDIT 10/05/2015:
found out that dev_push = false only works on physical devices, not in browser
I tried to add token to user before even registering the user
I'm having the same problem, seems not many answers online at the moment.
but even on real device, it won't save the token to user.
I just had to decide go live without push first, then use ionic deploy to follow up.
also I think you have to put this line
push.addTokenToUser(user);
inside the register callback according to this doc
http://docs.ionic.io/docs/push-usage
You also need to declare 'ionic.service.push' as a dependency in your angular module if you'd like to use it.
angular.module('starter', ['ionic','ionic.service.core', 'ionic.service.push'])
I have it like this and it works:
Ionic.io();
var user = Ionic.User.current();
if (!user.id) {
user.id = Ionic.User.anonymousId();
// save our newly created user
user.save();
}
var push = new Ionic.Push({});
push.register(function (token) {
console.log("Got Token:", token.token);
// now we have token, so add it to user
push.addTokenToUser(user);
// don't forget to save user to Ionic Platform with our new token
user.save();
});
// set this user as current, so we can acess him later
Ionic.User.current(user);
Did you use this
ionic config set dev_push true-if testing in emulator or laptop
ionic config set dev_pushfalse - if testing on the phone
ionic push --google-api-key Your API Key
ionic config set gcm_key Project Number
Your token is the registration id that is unique for a particular device. That is sent to you by android.
Your Phone (With the API Key)---------> to Google's GCM
Google GCM (recognises it's you via your Project number and API key) -----> Oh it's you let me make a note of it. (Save a token id in it's DB and send's one to you.)
You get a registration id unique for your device(will change if an app is uninstalled).
You call your server say hey it's me your user. Please Notify me if you get something.
Server obliges, says, okay dude, I got this. Saves the registration id with your details probably your username in it's DB.
Now from Server.
I need to inform my users about a great deal(or an accident or something).
Pull up all targeted registration Id's from DB(maybe on some condition)
registrationIds.push(regId) //in a loop
and sender.send(message, registration, function(err, result){
});
Send to Google. Google see's oh only these many people(not all maybe) from this API Key need a notification. no Problem I will notify them and you receive a notification, my dear friend.
As mentioned in the link , Adding token to the $ionicUser is done by doing , user.addPushToken(pushToken); .
For this to work you should first configure the app not to use developement pushes by ,
ionic config set dev_push true
After initialising Ionic.io and Ionic.push , load the user or create one with a new random id ,
Ionic.io();
var push = new Ionic.Push();
Ionic.User.load(localStorage.id).then(function (user) {
Ionic.User.current(user);
pushFactory.register(push, user);
}, function (error) {
/*the user with that id is not present , so create one with a random id and register the push */
});
The push factory is defined as below,
function pushFactory() {
return {
'register': function (push, user) {
push.register(function (pushToken) {
user.addPushToken(pushToken);
user.save().then(function (answer) {
console.log('user saved'+answer);
})
})
}
}
}

Send and read the SMS content sent via native SMS app in Cordova

I'm building an Ionic/Cordova app. From my application, user can click on a phone number in order to send SMS. When click on that number, native SMS app will open and then user can type his/her own SMS and send the SMS. Is there any way, from my app I can get the SMS content?
As you are using ionic/cordova, a SMS plugin is required to do such work.
Besides jsmobile SMS plugin, there is another one with more APIs:
http://plugins.cordova.io/#/package/com.rjfun.cordova.sms
As mentioned in the description:
sendSMS(address(s), text, successCallback, failureCallback);
listSMS(filter, successCallback, failureCallback);
deleteSMS(filter, successCallback, failureCallback);
startWatch(successCallback, failureCallback);
stopWatch(successCallback, failureCallback);
enableIntercept(on_off, successCallback, failureCallback);
restoreSMS(msg_or_msgs, successCallback, failureCallback);
Events
'onSMSArrive'
You can get the SMS content in either of the following ways:
implement the UI, get user's input, and call plugin's API to send the SMS.
Or,
let the default SMS app send the message, then read the SMS from the sent box.
BTW, the plugin works for Android only, FYI.
There is cordova-plugin-sms option, as #MikeX suggested, but notice that its license is not free use.
So I chose using Phonegap-SMS-reception-plugin, which is MIT license.
and then it just
var smsInboxPlugin = cordova.require('cordova/plugin/smsinboxplugin');
smsInboxPlugin.startReception (function(msg) {
alert(msg);
stopReadingSMS(smsInboxPlugin);
}, function() {
alert("Error while receiving messages");
stopReadingSMS(smsInboxPlugin);
});
function stopReadingSMS(smsInboxPlugin) {
smsInboxPlugin.stopReception (function() {
console.log("Correctly stopped SMS receiver");
}, function() {
console.log("Error while stopping the SMS receiver");
});
}
Are you saying you want to know what the user typed in another app? If so, I don't believe you can. In theory you can try skipping the real SMS app and using a plugin: http://plugins.cordova.io/#/package/com.jsmobile.plugins.sms
Nowadays there are ionic wrappers for cordova extensions. You can use $cordovaSMS (docs here)
module.controller('ThisCtrl', function($cordovaSms) {
document.addEventListener("deviceready", function () {
$cordovaSms
.send('phonenumber', 'SMS content', options)
.then(function() {
// Success! SMS was sent
}, function(error) {
// An error occurred
});
});
});
To see what the user is typing you can have them write the 'SMS content' inside your app. One you leave your app I don't think you can grab text from the native SMS field
you can use sms: url for opening native sms app for that you need to add
<access origin="sms:*" launch-external="yes"/> inside config.xml
after adding above line use sms link as follows
<a class="button icon-left ion-android-mail button-balanced button-outline" href="sms:9808350855">SMS</a>

geolocation confirm box showing my index file url in phonegap ios application

I'm creating an ios app with phonegap 3.2 I need users current location to search nearby users. When i tried to get current location of device with code
function onSuccess(position) {
device_lat = position.coords.latitude;
device_long = position.coords.longitude;
}
// onError Callback receives a PositionError object
function onError(error) {
alert("Share Your Location First.");
}
function onDeviceReady()
{
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
A confirm box appearing with following text.
"/Users/../Library/Application Support/iPhone Simulators/6.1/Applications/[App Code here]/demo.app/www/index.html" Would Like To Use Your Current Location.
Is it possible to costomise this text as its say Like
"MyApp Would Like To Use Your Current Location" ?
Also for android and other devices.
I'm posting a new answer since the last one was incomplete. In order to get the geolocation prompt title to show your app name and not the full path to the file you'll need to do two things:
Install the Cordova / PhoneGap geoLocation pluin (cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git)
Run the getCurrentPosition after deviceready has been fired.
$(document).ready(function(){
$(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
});
I removed cordova geolocation plugin and everything working well. I'm using phonegap 3. navigator.geolocation.getCurrentPosition(onSuccess, onError); is also a html5 function so no need to other changes. Now it giving confirm box with message.
"MyApp Would Like To Use Your Current Location"
MyApp is the title of index page.

InAppBrowser events not firing in Cordova 3.0.0 / Android

Any suggestions on why I'm not getting events?
I'm opening the browser after deviceready:
document.addEventListener('deviceready', app.login, false);
I register the event listener, the login function below is called as expected, the foobar page opens, but I never get the "loadstart" (or any other) callbacks that I register for:
login: function () {
console.log("login");
var authorize_url = "foobar";
var appInBrowser = window.open(authorize_url, '_blank', 'location=yes');
appInBrowser.addEventListener('loadstart', function(event) { console.log('loadstart'); });
}
As far as I can tell I'm following the Cordova docs example. Thanks.
Solution: Don't forget to manually install the plugin. Without the plug-in the browser will still show up, but events won't fire:
Use the command line interface:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

Categories

Resources