plot projects - Plot plugin is not initialised successfully in app - android

I am using plotprojects plugin for location based notifications in app: http://www.plotprojects.com/.
The app is build on ionic cordova framework.I am calling plot.init() inside $ionicPlatform.ready() function. However the plot.isEnabled () function gives output as Plot is disabled sometimes after launching the app. It happens randomly. Should I call plot.isEnabled() method later in the code to get correct status of plot?
$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.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
//org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
//window.localStorage.setItem("IsLaunched","YES");
var plot = cordova.require("cordova/plugin/plot");
plot.init();
console.log('after plot init');
plot.isEnabled(function(enabled) {
var plotEnabledState = enabled ? "enabled" : "disabled";
console.log("Plot is " + plotEnabledState);
}, function (err) {
console.log("Failed to determine whether Plot is enabled: " + err);
});

It takes some time before Plot is initialized. Plot initializes in the background. When calling plot.isEnabled() straight after calling plot.init() then it will return false. If you wait a second before calling plot.isEnabled() then it will return true.

Related

jQuery 'taphold' does not fire, while 'tap' does

In my flutter app I have html inside a webview and some javascript with jquery attached. I want to trigger different actions depending on if a list item receives 'tap' or 'taphold'. I'm using jquery-mobile 1.5.0-rc1.
My javascript is as follows:
$('div.board').on('taphold tap', 'div.thread, div.thread-special', function(event) {
console.log('event');
var $item = $(this); // The item that was clicked or held
var scope = $item.data('itemscope'); // No numbered IDs! You can find everything about the item
// etc.
var type = event.type;
if (type === 'tap') {
console.log('tap');
} else if (type === 'taphold') {
console.log('taphold');
}
});
When I tap, I can see a 'tap' in the console. When I taphold, nothing at all happens or appears on the console. Any idea why?

onSMSArrive cordova sms plugins executed more than once

I was developing an app that have capability to read sms content when the user get sms.
So I use ionic and cordova sms plugin to read the sms content. But when user get a sms and triggered the onSMSArrive event provided by the plugin, it did work and can read the sms content.
The problem is it execute (read the sms) more then once, tree times to be exact.
I place this code as a service in ionic.
app.factory('$smsarrive', [function() {
return {
periksa:function() {
if (SMS) SMS.enableIntercept(true, function() {
console.log("some debug hint here");
}, function(){
console.log("some debug hint here");
});
if(SMS) SMS.startWatch(function() {
//update('watching', 'watching started');
console.log("some debug hint here");
}, function(){
//updateStatus('failed to start watching');
console.log("some debug hint here");
});
document.addEventListener('onSMSArrive', function(e) {
var sms = e.data;
var isiSms = sms.body;
if (isiSms.match(/FC0019229/g)!=null) {
if (isiSms.match(/Berhasil/g)!=null) {
console.log("Isi pulsa Berhasil");
} else if (isiSms.match(/Gagal/g)) {
console.log("Isi pulsa Gagal");
} else {
console.log(isiSms);
}
} else {
console.log("some hint here");
}
console.log("ASLI : "+isiSms);
});
}
}
}])
and execute that service whenever a controller of a view is
$scope.$on('$ionicView.enter', function() {
$smsarrive.periksa();
})
Any suggestion? And also sorry for bad english.
i use this plugin
From what I understand in your code examples, you are executing the function "periksa" every time a view is entered ( that's what fires the '$ionicView.enter' event). Then also, you are creating an EventListener for SMS messages every time you execute 'periksa' (every time a view is entered).
So, if you have entered three views, you would have three listeners firing for the arrival of an SMS onSMSArrive.
So, I think you should only Start Watching, and add the EventListener, once, when starting the app (in app.js, inside .run, when $ionicPlatform.ready()).
.run(function($ionicPlatform, $smsarrive) {
$ionicPlatform.ready(function() {
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.styleDefault();
}
if(( /(ipad|iphone|ipod|android)/i.test(navigator.userAgent) )) {
if (! SMS ) { alert( 'SMS plugin not ready' ); return; }
SMS.startWatch(function(){
console.log('Watching');
}, function(){
console.log('Not Watching');
});
document.addEventListener('onSMSArrive', function(e){
var data = e.data;
$smsarrive.periksa(data);
});
} else {
alert('need run on mobile device for full functionalities.');
}
});
Then, your 'periksa' function should only receive the data as a parameter, for processing and disposing of the results.
Let me know if this was helpful, i'm also studying this framework and I have this plugin working in my App.

ionic + cordova plugin and background mode

I'm making an app with ionic for car drivers. The app takes coordinates every one minute and write them on remote server, this helps me to tracking route and show cars on Google map.
I use Cordova plugin and it works fine except when screen turns off or the app goes into the background. I installed katzer cordova-plugin-background-mode, when the app go into background I see the message : app is now in background, the plugin informs me but nothing else, the app stopped! .
No data sent to remote server, when I resume the app all is back to normal, I use Android platform. How can i solve?
app.js code
angular.module('starter', ['ionic', 'ngCordova','LocalStorageModule', '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);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
cordova.plugins.backgroundMode.enable();
});
})
.....
controllers.js
angular.module('starter.controllers', [])
.controller('GeoCtrl', function($scope, $cordovaGeolocation, $cordovaNetwork, $http, $interval) {
var reloadCoordinates = function() {
var watchOptions = {
timeout : 10000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
// error
},
function(position) {
//Latitudine e Longitudine
var lat = position.coords.latitude
var lon = position.coords.longitude
$scope.latitude = lat
$scope.longitude = lon
$http.post('http://192.168.1.2/get-data.php', { "lat": lat, "lon" : lon }).then(function(resp) {
console.log('Success Lat:'+resp.data.lat+' Lon:'+resp.data.lon);
watch.clearWatch();
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
});
};//end reloadCoordinates
$interval(reloadCoordinates, 60000);
reloadCoordinates();
})
I know this is an old thread, but I did manage to get this working, with:
cordova.plugins.backgroundMode.on('enable', function(){
//your code here, will execute when background tasks is enabled
loop();
});
function loop(){
console.log("loop");
$timeout(loop, 1000);
}
cordova.plugins.backgroundMode.enable();
#Cristian,
after enabling plugin, you should call your function or write your logic in this function.
cordova.plugins.backgroundMode.onactivate = function() {
// your logic here
// or call any other service, factory function
};
Are you trying to make an app that does something every x minutes, even when the app is in the background and/or the screen is turned off.... tried backgound-mode plugin but it only works reliably when the phone is plugged in... did you ever found a solution to this?
Install the plugin using the cordova command line utility:
$ cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git
here's how i use it along with the background mode plugin so the app is never in background and always running as a service...:
if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
}, function() {
console.log('Failed to set');
});
}
Final Step Deactivate your plugin when you finished your service as
cordova.plugins.backgroundMode.disable()

Cordova: (ion-google-place) google map api callback not working on Android Phone

i am using ion-google-place directive in my ionic project and when i run it in the ripple I can see that this directive works as expected, however when i deploy it on my Android phone the search bar comes up but when i type no drop down is shown.
I tried to debug the code and can see the issue to be around the following code:
var geocoder = new google.maps.Geocoder();
geocoder.geocode(req, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
scope.$apply(function () {
scope.locations = results;
});
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
the callback function is never called when running within the android phone, however from ripple its working.
Any ideas as to what I may be missing ?
EDIT 1:
I created a Blank Cordova project and added the refrences to angular and google map. Then added a button and added a ng-onclick to that button as below
$scope.onButtonClick = function () {
var api = new google.maps.places.AutocompleteService();
api.getPlacePredictions({ input: "Banga" }, function (results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log("google place... success");
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
Now I see that google is not defined when debugging the Android Phone, where as same when being debugged in ripple, it is working.
is there something on the phone that can prevent the maps from being available to the app?
Regards
Kiran

Preventing camera to save a file till all my processing is done in Titanium SDK

I am using titanium sdk for mobile app development.
I was just searching for any way that i can prevent the camera from saving the image. I dont want to save the image till a few steps down the line so that all the information has been verified.
What i mean to say is that suppose after after clicking the image through the app if user selects the cancel button the image should not be present in the gallery.
Functionality is needed both on IOS and android.
Thanks a lot ...
You need to set the saveToPhotoGallery to false and on the success function of the Titanium.Media.showCamera() put your logic and when they click on the save button save to the gallery
Titanium.Media.showCamera({
success:function(event) {
// called when media returned from the camera
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
//
//add your logic here
//
//onSave
Titanium.Media.saveToPhotoGallery(event.media);
} else {
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function() {
// called when user cancels taking a picture
},
error:function(error) {
// called when there's an error
var a = Titanium.UI.createAlertDialog({title:'Camera'});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Please run this test on device');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
saveToPhotoGallery: false,
allowEditing: true,
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
});

Categories

Resources