I have a button when pressing it performs the request for some data. So, in my ts file of the page where the button is, I call the function in my provider.
The main problem comes when I compile my application for android platform (Generate apk with ionic cordova build --release android, then I Sign the apk, align and install it). In that case, when I press the button nothing happens, I debugged the code (I added some alerts), but only the first line of the function (The alert that I added) is executed, never returns anything.
But.. If I run the app with the commands: ionic cordova run android -l and ionic serve -l. It works like a charm (The provider return the data requested)
I mean, the problem is only when I generate the APK to install it into my device
I also tried with HttpClient but the problem persists.
The code of my Provider is:
Search(path): Promise<any> {
// ------------- The alert is shown
return this.http.get(path)
.map(res => res.json())
.toPromise()
.then(
response => {
// ------------- The alert is not shown
if (typeof response.user.name !== "undefined") {
this.storage.set('users', JSON.stringify(response));
return response;
} else {
return null;
}
},
error => {
// ------------- The alert is not shown
return null;
});
}
I also tried with something like this:
Search(path): Promise<any> {
// ------------- The alert is shown
return null;
}
But, also in this case the return line is never executed, only the alert is shown.
The code when I call my provider function in the page where the button is:
this.APIService.Search(final_path).then(res => {
if (res) {
this.storage.get('users').then(responseJson => {
if (responseJson) {
this.navCtrl.push(ObtenerPage);
}
});
} else {
this.presentToast("Bad request");
}
});
Related
I created a simple app using Meteor 1.3, which has only one method. It works like that: When a button is clicked, the method is invoked - it calculates a specific value and returns the result.
The app works perfectly on the localhost server, but when I launch it on my device with "meteor run android-device", it cannot access the method (simply opens the app, but nothing happens when I press a button.
Do you know how I could resolve this?
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { ReactiveDict } from 'meteor/reactive-dict';
import './main.html';
Template.check.onCreated(function checkOnCreated() {
this.state = new ReactiveDict();
});
Template.check.events({
'click .checkit'(event, instance) {
Meteor.call('code.check', function(error, result){
if(error){
console.log('Error from the client side!');
} else {
instance.state.set('fett', result.titles[0]);
}
});
},
});
Template.check.helpers({
fett() {
const instance = Template.instance();
if (instance.state.get('fett')) {
return instance.state.get('fett');
} else {
return 'Value still not known...'
}
},
});
Ensure your smartphone's WiFi is turned on and it connected to the same WiFi network as you computer where meteor app is running. Then everything should work fine.
Also, I recommend to use chrome://inspect feature (more info here) in order to debug your app on Android. Then, you will be able quickly investigate any problems with mobile app.
I made simple application. Added android and desktopbrowser environments. Android app works fine.
While preview desktopbrowser environment getting Error Access Denied Reload dialog box infinite times.
Made below two changes in "worklight.properties" file.
mfp.session.independent=false
mfp.attrStore.type=HttpSession
Tried with restarting server and eclipse as well.
Code to reproduce below:
function wlCommonInit(){
WL.Client.connect({
onSuccess: onConnectSuccess,
onFailure: onConnectFailure
});
}
function onConnectSuccess(){
alert("Connected to Server");
WL.Client.checkForDirectUpdate();
}
function onConnectFailure(){
alert("Connection Failure");
}
$("p").click(function(){
alert("Paragraph Clicked");
getData();
});
function loadFeedsSuccess(result){
invocationResult = result.invocationResult;
alert(JSON.stringify(invocationResult.firstName));
alert(JSON.stringify(invocationResult.lastName));
}
function loadFeedsFailure(error){
console.log("Feed retrieve failure");
alert(JSON.stringify(error));
alert("Feed retrieve failure");
}
function getData() {
var invocationData = {
adapter : 'Test',
procedure : 'getAdapter',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadFeedsSuccess,
onFailure : loadFeedsFailure,
});
}
I cannot reproduce this.
Created a new project in IBM MobileFirst Platform Studio 7.1.0.00-20160321-2138
In server\conf\worklight.properties I have set mfp.attrStore.type=HttpSession and mfp.session.independent=false
Added the Mobile Web environment
Added code for WL.Client.connect() in main.js -> wlCommonInit()
Run As -> Run on MobileFirst Development Server
Preview in Console
I got a dialog showing "success" (the success callback of onSuccess).
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()
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
I am using phonegap to develop my app on Android and iOS. So far, I have managed to implement the facebook connect plugin for Android and it works pretty well.
There is one thing I am unable to do, it is how to handle the plugin errors. For instance, when there is no network connection, the FB.login(...) does not work and I got an alert from the facebook-js-sdk.js:
line 5105 :
// CORDOVA PATCH
// If the nativeInterface arg is specified then call out to the nativeInterface
// which uses the native app rather than using the iframe / popup web
if (FB._nativeInterface) {
switch (params.method) {
case 'auth.login':
FB._nativeInterface.login(params, cb, function(e) {alert('Cordova Facebook Connect plugin fail on login!' + e);});
break;
How can I intercept that alert and display my own error? here is the code I am using for the login:
login: function(success, error) {
FB.login(function(response) {
if (response.authResponse) {
//some code ..
if (success && typeof(success) === "function") {
success();
}
} else {
alert('User cancelled login or did not fully authorize.');
if (error && typeof(error) === "function") {
error(false);
}
}
}, {scope: 'email'});
}
PS: I never enter in the else block even if I cancel the login authorization, I've got the same alert.
Am I missing something?
Thank you very much for your help.