Console log not firing in promise on android device - android

I'm developing an Ionic app in which I try to load the device's contacts using native plugin. There's an asynchronous call with some console logs inside but the logs are not appearing when run on android 5.1 device. The rest of the code in promise are fired, only the logs are not fired. In the browser, they appear.
public loadContactsFromDevice(): void {
console.log('ContactsProvider loadContactsFromDevice INIZIO');//this is fired
this.contacts.find(
['displayName', 'name', 'birthday'],
{ filter: "", multiple: true })
.then(resultData => {
console.log('ContactsProvider loadContactsFromDevice resultData:' + resultData);//this is not fired
this.allContacts = resultData;
this.setContactsList(this.allContacts);
});
console.log('ContactsProvider loadContactsFromDevice FINE');//this is fired
}

I found the solution. Previously I put the call to method that retrives the contacts in app.component.ts insideplatform.ready().then(){} .. When i put it outside the platform.ready() the logs are visible. I don't know why but it works.

Related

EXPO Receiving Notifications works when the application is in the background/foreground, but not when the application is killed

I just learned about notifications in the expo, now I have successfully sent notifications and I have also managed to get data from the notifications I sent, the problem is, if the application is in background or foreground, addNotificationResponseReceivedListener is working properly (redirect to another page), but if I close the application, and I receive a notification, then I press the notification, the application opens but the addNotificationResponseReceivedListener function is not running, I try this in a standalone application
what i’m using:
“expo”: “~40.0.0”,
“expo-notifications”: “^0.9.0”,
here’s my example code in Home.js:
componentDidMount() {
//another code..
Notifications.addNotificationResponseReceivedListener(
this._handleNotificationResponse
);
}
_handleNotificationResponse = (response) => {
console.log(
"CONSOLE FROM NOTIF: " +
JSON.stringify(response.notification.request.content.data.from)
);
if (response.notification.request.content.data.from== "GEMASS") {
this.props.navigation.navigate("goToPage", {
//another code...
});
} else {
}
};
here’s my file tree:
App.js
Components
- Home.js
and here’s my terminal looks like when i run on expo client:
clickme
can you guys help me? it means a lot :)

Web Share API navigator.share problem when canceling share dialog IOS and Android

When using MOBILE SHARE (navigator.share), canceling the Share flow causes an unexpected error to appear.
The message can be acknowledged and user is allowed to proceed but this error response is unexpected.
STEPS TO REPLICATE
1.Tap the SHARE icon to initiate the share dialog then:
2.a on iOS, find and tap the close [ x ] control in the upper righthand corner of the dialog to dismiss
2.b on Android, swipe the share overlay down (or whatever way to close/exit this dialog?)
3.The error "AbortError: About due to cancellation of share" appears when:
on iOS, immediately on cancellation
on Android, when attempting to re-engage the Share control.
The error message:
www.example.com says: AbordError: Share canceled
Im using this Vue plugin https://github.com/GabrielBibiano/vue-navigator-share
This is not an issue with Vue.js or any plugin, but something that navigator.share function does.
It is throwing this on canceling/dismissing share action.
Check this example on phone which supports navigator.share.
(NOTE: open this page as desktop site since phones can not run examples)
You can also see this (LOC: 303): https://chromium.googlesource.com/chromium/src/+/34eacf936ac3255925c5045c4385dc9b5f19fa78/chrome/android/javatests/src/org/chromium/chrome/browser/webshare/WebShareTest.java
const share = async () => {
try {
await navigator.share({ url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' });
} catch (e) {
if (e.toString().includes('AbortError')) {
alert('Hello world aborted :(');
}
}
}
<button onclick="share()">share (only for phones)</button>

ionic 3 geo-location not working for the second time

I have a problem using Geolocation on Android device.
I create an Ionic 3 application.
I use Geolocation ( [https://ionicframework.com/docs/native/geolocation/ 13]).
I use the sample code provided there.
The problem is that, the code works in Browser but whenever I upload it on an Android device, it does not work.
When I start the app on device the alert for location permission is prompted.
I press Allow.
Then in the android tray an icon appears that says “Searching for GPS”.
After timeout expires I got the error for timeout and no location.
The strange think is this:
If I close my app, then open google maps ( or other app using gps position ) and reopen my app works as it should.
I don’t know what to do.
The permissions are fine :
and everything was installed properly.
Can anyone help please?
i got it actually i have to pass apikey with that like
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_KEY"></script>
in the index page
without this key it sometime works but not sure everytime.
Note : this key is only generated when you have a valid gmail a/c (by providing DOB/CreditCard nos) although its free .
try this, it should work
ionic cordova run android --prod
--prod makes production build apk
import { LocationAccuracy } from '#ionic-native/location-accuracy';
declare var navigator
Above
#Component
watchPosition() {
this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
() => {
var options = {
timeout: 500,
maximumAge: Infinity
};
this.watch = navigator.geolocation.watchPosition((data) => {
let latlng: LatLng = new LatLng(data.coords.latitude, data.coords.longitude);
}, (error) => {
console.log("error watch", error)
}, options);
}
}, error => {
alert('Error requesting location permissions' + JSON.stringify(error))
});
}
}

How to implement WAIT for screen elements load in ionic 2 hybrid mobile application using protractor

How to implement wait for screen elements load in ionic 2 hybrid mobile application using protractor.
As I am testing the IONIC Mobile application and not able to use wait without browser.sleep(), Because browser instance is not working in application.
Please help me to resolve this issue.
It's been a while, but I've had some success testing Ionic with Protractor with the following helper method:
waitForIonic: function () {
//Register a promise with protractor, so the browser waits for it
var deferred = protractor.promise.defer();
let clickBlock = element(by.css('.click-block-active'));
//if there's a click block, wait for it to be gone, otherwise just wait 1 sec
if (clickBlock.isPresent()) {
var untilClickBlockIsGone = ExpectedConditions.not(ExpectedConditions.visibilityOf(clickBlock));
browser.wait(untilClickBlockIsGone, 20000).then(() => {
browser.driver.sleep(1000);
//We've fulfilled the promise, so
deferred.fulfill();
});
}
else {
browser.driver.sleep(1000);
//We've fulfilled the promise, so
deferred.fulfill();
}
//Return the promise (which hasn't been fulfilled yet)
return deferred.promise;
}
Then use it like so:
//Wait for ionic animiations, Click logout
module.exports.waitForIonic().then(() => {
logoutButton.click();
});

cordova facebookConnect - login refresh on samsung g s3

I have recently decided to test Cordava FacebookConnect (https://github.com/mgcrea/cordova-facebook-connect).
I have managed to install on an Android project which works on the Android Virtual Device. But when I plugin my Samsung GS3, The device has a fit and just keeps refreshing the application.
My code is very basic:
var app = {
initialize : function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
var facebookConnect = window.plugins.facebookConnect;
console.log('ready');
facebookConnect.login(
{
permissions : ["email", "user_about_me"],
appId : "3560694656564117"
}, function(result)
{
console.log("FacebookConnect.login:" + JSON.stringify(result));
if( result.cancelled || result.error ) {
console.log("FacebookConnect.login:failedWithError:" );
}
});
}
};
What is weird is that the console logs "ready" every second which is not inside the facebookConnect callback. It as if I have previously logged in, revisited the app, the plugin verifies my credentials, the dialog closes and then it starts again! If I comment out the facebookConnect login method it just loads as normal, the console logs "ready" only the once.
Has anyone come across this before?
Regards
Make sure you setup the native android app section in the facebook app dashboard. Especially the hash key section.
You should indicate whether the facebook callback got called or not.
You can always look in the logcat if there are fb errors that come out.

Categories

Resources