Notification action buttons action without showing the app - react-native

I have a local notification with action buttons 'Start' and 'Remind later'. When I click on either of two, the app opens. I want to keep it for the Start button, but for Remind later button I want to silently run some code (reschedule notification on a later time) without opening an app.
Is this possible to do?
function onOpened(notification) {
if (notification.action == 'Start') {
cancelNotification(notification.id)
NavigationService.navigate(notification.title)
} else {
cancelNotification(notification.id)
// reschedule
let dateTime = new Date(notification.fireDate)
dateTime.setMinutes(dateTime.getMinutes() + 30)
scheduleNotification(notification.id, notification.title, notification.message, dateTime)
}
}
This code works, but as I said, it bring the app to the foreground, and I'd like to avoid it.

You need to include your full code if you looking for help, but from your tags, I assume you are using React Native Push Notifications. If that's the case you might want to look at this Action click brings the app from background to foreground issue. Basically, you need to go through some native codes and change a few lines.

Related

I can't dismiss my keyboard in my react native app after an alert

I'm currently trying to close the keyboard programmatically:
https://imgur.com/a/3gBlyZp
But it does not work. It actually closes, then reopens when the screen changes, whereas there is no input on the second screen.
I already tried to put Keyboard.dismiss() just before changing the screen and in the componentDidMount() of the second screen, without success.
This happens everytime you have an open Alert while trying to hide the Keyboard. It's quite hacky but you can try to wrap your Alert in a timeout.
setTimeout(() => {
//... open your alert here
}, 50)

How to implement correct Back behaviour when using Frame.Navigate?

I have a Windows 10 Universal Windows Platform app with multiple pages, a main page, a list page and a details page and use the following to navigate to List page:
this.Frame.Navigate(typeof(ListPage), parameter);
When you are on the list page you can select an item which will launch a details page like so:
this.Frame.Navigate(typeof(DetailsPage), parameter);
Which works fine, the parameter is a selected Id or information then when using the Back button which on a Desktop app or Phone uses:
this.Frame.GoBack();
This always returns to the MainPage, that is when go from Main, to List to Details hitting back goes to Main, how do I get the GoBack to Go back to the previous page, it always seems to go home rather than the user expected behaviour, an ideas how to resolve this?
I’ve seen this before when you subscribe to the HardwareButtons.BackPressed event (or whatever the equivalent is in a Win10 UWP app) on a page, but then don’t unsubscribe from it. This means two event handlers get called when pressing Back, and both event handlers call Frame.GoBack().
I always subscribe to the event in the page’s NavigatedTo event, and unsubscribe in the NavigatedFrom event.
Could this be happening with your app?
If every page in your app should have the same behaviour, i.e. go back to the previous page, then subscribe to the back button event in the app class as suggested by #RoguePlanetoid in the comments:
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
The OnLaunched method would be a good place to do this. Don't forget to tell the OS to display the back button when the app is running on a desktop or tablet:
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Then, add an event handler in the app class like this:
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
If you want different behaviour on different pages when back is pressed, i.e. ask the user to confirm losing their changes or something, then subscribe to the back button event in a pages OnNavigatedTo method (the code will be same as above), but make sure you unsubscribe in the page's OnNavigatedFrom event:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
SystemNavigationManager.GetForCurrentView().BackRequested -= this.OnBackPressed;
base.OnNavigatedFrom(e);
}

Durandal view no more displayed if user click quickly on menus

I use Durandal 2.0 & Breeze in my SPA.
I have a sidebar menu for my drivers (Chauffeurs) where user can click on submenus (Récents, Disponibles, Indisponibles) for calling my view with different parameters. This will fill a koGrid with data. The data is fetched in the activate call and the binding of the koGrid is done in the compositionComplete.
Everything goes well most of the time. Things goes wrong when I click very quickly on submenus (calling the same view). Example: I click on 'Récents' and immediately (without waiting for the view to display) I click on 'Disponibles'.
I have the following for the activate:
var activate = function (filterParam) {
filter(filterParam);
pagedDataSource.getDataFunction = getData;
pagedDataSource.getPredicatesFunction = getPredicates;
return pagedDataSource.reload();
};
And I have the following code for the compositionComplete:
var compositionComplete = function (view) {
bindEventToList(view, '.kgCellText', gotoDetails);
$('#mySearchGrid').attr('data-bind', 'koGrid: gridOptions');
ko.applyBindings(vm, document.getElementById('mySearchGrid'));
};
When I trace the activity, I noted that if user click quickly on submenus, the activate does not have the time to finish and is called again (for the second click of the user) and the compositionComplete does not execute. Then after that, nothing more happened visually. It seems blocked.
Any idea how can I prevent this problem?
Thanks.
The migration to the latest Durandal version 2.0.1 fixed the problem.

How to Handle The Notification (Shell_NotifyIcon) to perform Some action when user clicked on It?

Iam NewBie, I have Created Tray Icon for my Application
with
void createTrayIcon(LpSTR msg)
{
memset(&m_NID, 0 , sizeof(m_NID));
m_NID.cbSize = sizeof(m_NID);
// set tray icon ID
m_NID.uID = ID_SYSTEMTRAY ;
// set handle to the window that receives tray icon notifications
ASSERT(::IsWindow(GetSafeHwnd()));
m_NID.hWnd = GetSafeHwnd();
// set message that will be sent from tray icon to the window
m_NID.uCallbackMessage = WM_TRAYICON_EVENT;
StringCchCopy(m_NID.szInfo, ARRAYSIZE(m_NID.szTip),msg);
StringCchCopy(m_NID.szInfoTitle, ARRAYSIZE(m_NID.szInfoTitle), L"DuOS");
// fields that are being set when adding tray icon
m_NID.uFlags = NIF_MESSAGE|NIF_ICON|NIF_INFO;
// set image
m_NID.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
if(!m_NID.hIcon)
return FALSE;
return Shell_NotifyIcon(NIM_ADD, &m_NID);
}
I Am Showing the Notifications By Using
Shell_NotifyIcon(NIM_MODIFY , &m_NID);
My problem is I want to handle that Notification i.e, If user clicks on that
Notification I need to do some action, How to achieve this
I am trying for this from last two days I had Googled Lot of times and searched lot of blogs But I cant, Anyone Please Help me Out
Finally I Got the Answer ,
there was a NIN_BALOONUSERCLICK flag was there, if User clicks on Baloon it will return this Flag...

ActivityIndicator without dialog box on android?

Im new to titanium and i'm trying to create an a indeterminate preloader (or activity indicator as it is called in titanum). The problem is that on android, the activty indicator is automatically placed in a dialog box, preventing users from interacting with the app until the dialog is dismissed.
Is there any way to just add a simple indetermindate preloader without using a dialog box in android?
Thanks.
According to Appcelerator Docs
Activity indicators must be used differently on Android and iOS:
On Android, the activity indicator is a modal dialog that blocks the UI. Calling show displays the indicator, and calling hide removes it.
One option that you can use is setting cancelable property to true which let the user to cancel the activity indicator dialog by pressing the BACK button.
Appcelerator docs says :
An activity indicator can be used to show the progress of an operation
in the UI to let the user know that some action is taking place. An
activity indicator consists of a spinning animation and an optional
text message, and is used to indicate an ongoing activity of
indeterminate length. To show progress, use Titanium.UI.ProgressBar
instead.
Titanium.App.addEventListener('show_indicator', function(e) {
showIndicator(e.title_msg, e.sub_msg);
});
function showIndicator(title_msg, sub_msg) {
var actIndG = Titanium.UI.createActivityIndicator({
style : Titanium.UI.iPhone.ActivityIndicatorStyle.BIG,
top :10
left : 130,
height : 60,
width : 60,
height : screenheigth,
width : screenwidth
});
indView.add(actIndG);
indWin.open();
}
Up vote or Mark best if it helps you.