I am using ionic 2 local notification. Local notification not working when I remove the app from background.
This is sample code
this.localNotifications.schedule({
text: 'Delayed ILocalNotification',
every:'minute',
at: new Date(new Date().getTime() + 60000),
led: 'FF0000',
sound: null
});
try this push notification. https://ionicframework.com/docs/native/push/
the local notification requires the app running in background.
Related
I created a PWA app which sends API call to my domotic server and prints the response on the home page (e.g. outside temperature and vacuum robot status).
While all the data get refreshed at very first app opening, if I minimize the app whithout completely shutting it off I have no data refreshing at all.
I was wondering how to force a refresh every time the app gets re-opened without having to do it manually (no pull-down to refresh, no refresh-button).
Found myself the solution adding the following code in service worker:
self.addEventListener('visibilitychange', function() {
if (document.visibilityState === 'visible') {
console.log('APP resumed');
window.location.reload();
}
});
Here is the solution that works.
You can place this code wherever you have access to the window object:
window.addEventListener("visibilitychange", function () {
console.log("Visibility changed");
if (document.visibilityState === "visible") {
console.log("APP resumed");
window.location.reload();
}
});
Consider this may affect user experience or data loss with a forced reload every time the user swipes between apps.
Expo sdk: 40
responseListener.current =
Notifications.addNotificationResponseReceivedListener((response) => {
axios.post("https://<logUrl.onOurServer.com>", {
test: "background",
});
});
addNotificationResponseReceivedListener // dont work when app's not running
This method sends me a notification mail when app is running but if the apps is not running, I can't capture this event from a cold start. Is there a permission or something for this to work?
I've just copy pasted the code from https://docs.expo.io/versions/latest/sdk/notifications/
and just added logging to a https endpoint, it does not work on cold start.
I am using both local and push notification in my app and i receive notification for both in background and foreground but i just want to receive only local notification in foreground.
You must threat application state in didReceiveRemoteNotification
and use UIApplicationState (can be .active in Swift or UIApplicationStateActive in Objective-C for example) see documentation apple docs
I want create application with ionic 2 that it send sms when user shaked mobile and so my app must be in background mode
I search and find this plugin for set app to background
https://github.com/katzer/cordova-plugin-background-mode
but how detect shake device when use this plugin ?
I have never worked with the background-plugin, but if it lets you run the app indefinitely in the background, you should be able to use the shake plugin to detect shakes: https://ionicframework.com/docs/native/shake/
Try to add
const watch = this.shake.startWatch(60).subscribe(() => {
// do something
});
to your app.component.ts and see if it works.
We have developed a google glass ware(timeline based) app. In that first we will send some timeline cards to the glass with some inbuilt menu items and custom menu items.
and we have configured the proxy url for getting notifications for time line.
It worked fine for so many days.
But After Google Glass XE-16 update we are not getting the timeline notifications
Can you please guide us inresolving the issue.
Hi Prisoner,
for inserting timeline we have used the following code:
global $base_url="http:\/\/mysite.com\/mirror";
$client = get_google_api_client();
$client->setAccessToken(get_credentials($_SESSION['userid'])); // A glass service for interacting with the Mirror API
$mirror_service = new Google_MirrorService($client);
$new_timeline_item = new Google_TimelineItem();
$new_timeline_item->setText('Hey I am testing new');
$notification = new Google_NotificationConfig();
$notification->setLevel("DEFAULT");
$new_timeline_item->setNotification($notification);
$menu_items = array();
$custom_menu_item = new Google_MenuItem();
$custom_menu_value = new Google_MenuValue();
$custom_menu_value->setDisplayName("Add Item");
$custom_menu_value->setIconUrl( $base_url . "/static/images/tulip.jpg");
$custom_menu_item->setValues(array($custom_menu_value));
$custom_menu_item->setAction("CUSTOM");
$custom_menu_item->setId("add_to_cart_item"); // This is how you identify it on the notification ping
array_push($menu_items, $custom_menu_item);
$new_timeline_item->setMenuItems($menu_items);
insert_timeline_item($mirror_service, $new_timeline_item, "image/jpeg", file_get_contents($base_url . "/static/images/tulip.jpg"));
for this we are trying to add new custom menus and built in menus like (pin,delete,share,send)
To subscribe to notifications we have used the Google glass Php mirror api function.
subscribe_to_notifications($mirror_service, "timeline", $_SESSION['userid'], $base_url . "/notify.php");
All these are working fine before XE-16 version update. After updation we are not able to get notification for time line card notifications
This is a known issue with sending image attachments. See details here:
https://code.google.com/p/google-glass-api/issues/detail?id=491
So the part of your code that has to change is:
insert_timeline_item($mirror_service, $new_timeline_item, "image/jpeg", file_get_contents($base_url . "/static/images/tulip.jpg"));
Needs to change to:
insert_timeline_item($mirror_service, $new_timeline_item, null, null);
And use setHTML instead of setText and include an img element with a src tag that points to a web URL. E.g.:
<img src="http://example.com/static/images/tulip.jpg" />
Note that you also have to factory reset your Glass. You can tell if you have the problem by trying to run a menu command and the spinning double arrow in the bottom right corner gets stuck and an a crash stack trace is visible on ADB logcat output on the Glass. So to fix the problem, first you have to not use image attachments, and second you have to reset the Glass to fix the broken timeline sync on the Glass.