I am running this using phonegap. When i run in Android the logout box is correct and its showing "confirm" as title in the logout box. Even in ios everything is perfect but the logout box shows title as "index.html"(which is the current page name)
$rootScope.logout=function()
{
response=confirm(GetLocalString("HMLOGOUTMSG",_language));
if(response==true)
{
logout();
}
else
{
menuchk();
}
}
I dont want the title as "index.html". Can you suggest a method to not display the title as "index.html"
In ios PhoneGap pages will show the page name in alert, you need to use a plugin for notification.
To add the plugin run this code.
cordova plugin add cordova-plugin-dialogs
Usage
navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
message: Dialog message. (String)
confirmCallback: Callback to invoke with index of button pressed (1,
2, or 3) or when the dialog is dismissed without a button press (0).
(Function)
title: Dialog title. (String) (Optional, defaults to Confirm)
buttonLabels: Array of strings specifying button labels. (Array)
(Optional, defaults to [OK,Cancel])
Example
function onConfirm(buttonIndex) {
alert('You selected button ' + buttonIndex);
}
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
['Restart','Exit'] // buttonLabels
);
The callback takes the argument buttonIndex (Number), which is the index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.
Documentation
Now its working fine,
$rootScope.logout = function () {
function onConfirm(buttonIndex) {
if (buttonIndex == 1) {
logoutfunc();
}
else {
menuopenchk();
}
}
navigator.notification.confirm(
'Are you sure to logout?',
onConfirm,
'Logout',
['Yes', 'Not Now']
);
}
Related
When I use this code:
function dialogConfirm() {
var message = "Am I Confirm Dialog?";
var title = "CONFIRM";
var buttonLabels = "YES,NO";
navigator.notification.confirm(message, confirmCallback, title, buttonLabels);
function confirmCallback(buttonIndex) {
navigator.notification.alert("You clicked " + buttonIndex + " button!",null,"helo","Nic");
}
}
However on android when I deploy with Cordova and I click on one of the btns of confirm the alert does not popUp so I tried with some text and I found out that the function confirmCallBack is never called whatever btn I click so does anyone know what can I do to call the confirmCallBack function or is it just a bug with the plugin in android. I remind you that on Windows Browser it works perfectly so the issue is either with the library or with my device it is a Moto G 3rd Generation android 7.0.1 Thanks in advance!
Your options buttons are a string instead of an array.
message: Dialog message. (String)
confirmCallback: Callback to invoke with index of button pressed (1,
2, or 3) or when the dialog is dismissed without a button press (0).
(Function)
title: Dialog title. (String) (Optional, defaults to Confirm)
buttonLabels: Array of strings specifying button labels. (Array)
(Optional, defaults to [OK,Cancel])
Try this sample from the original Dialogs plugin documentation:
function onConfirm(buttonIndex) {
console.log('You selected button ' + buttonIndex);
navigator.notification.alert('You selected button ' + buttonIndex);
}
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
['Restart','Exit'] // buttonLabels
);
I want to send a push notification from server to an ionic client and show this notification in client like a phone call (mobile device should play a sound and show 'Accept' or 'Reject' buttons with caller information). It should work if mobile app is not running or in background, that's why I decided to use FCM messages.
this.storage.get('firebase_token').then((token) => {
console.log('Orders get firebase token and call register. Token: ' + token);
this.agentService.registerPushNotifications(token, () => {
this.firebase.onNotificationOpen().subscribe((notification) => {
// How to open the app and show the page with a ringtone ??
});
});
});
How can I open the app and show the call page with a ringtone in incoming push notification? Or maybe there is a better way for this kind of feature.
What you are asking for (the same format like a phone call) isn't possible with Ionic. You can however redirect the user to a view inside the application where you ask him to take action.
Take the following example for push notification. In app.components.ts I initialize this function when the platform is ready
initializePushNotifications() {
let pushObject = this.push.init({
android: {
senderID: 'Your ID Here',
icon: 'logo'
},
ios: {
alert: true,
badge: false,
sound: true
},
windows: {}
});
if (!pushObject['error']) {
pushObject.on('registration').subscribe((data: RegistrationEventResponse) => {
// Whatever you want to do
}, err => {
console.log('Couldnt register:', err);
})
pushObject.on('notification').subscribe((data: any) => {
let self = this;
// When the user click the push notification
if (!data.additionalData.foreground) {
switch (data.additionalData.entity_type) {
case 'takeAction':
this.openView(data.additionalData.user_name, data.additionalData.id);
break;
......
}
}
});
pushObject.on('error').subscribe((e: any) => {
console.log(e.message);
});
} else {
console.error(pushObject);
}
}
See, in the pushed message we add an object under the key additionalData where you can pass whatever you want. You can pass something like entity_type with the value takeAction. When the user click it, you can open a new view and pass additional parameters like the name of the user and the id of the entity or whatever.
On this screen you can open an alert asking the user to click yes or no and based on his input you fire the correct request.
Note
I know this is different from what you were asking for but your request cannot be fulfilled using Ionic.
When alert/confirm box is popped up on screen and I press device's back button, then the poped up alert/confirm box is getting close(without firing any event). How can I avoid this?
Below is the calling code:
**var buttons = [
{
text : Messages.LBL_OK,
handler : doLogout
}
];
showSuccess(Messages.ALERT_FILING_CONFIRMATION,buttons);**
function showSuccess(text,buttons){
showDialog(Messages.LBL_CMN_DOALOG_SUCCESS_TITLE, text, buttons);
}
function showDialog(title,text,buttons){
if(title == null || title == undefined){
title = Messages.LBL_CMN_DOALOG_TITLE;
}
if(buttons == null || buttons == undefined){
buttons = [
{
text : Messages.LBL_OK,
handler : defaultOK
}
];
}
WL.SimpleDialog.show(title,text,buttons);
}
This is the expected behavior in Android.
However, if you'd like to avoid this default behavior, you could use the WL.App.overrideBackButton API in key locations in your code so that the button will 'do nothing'. When you're done, you can then use WL.App.resetBackButton to reset the back button's behavior back to its default state.
For example:
WL.App.overrideBackButton(callback);
function callback(){
// doing nothing...
}
You could use the above before calling WL.SimpleDialog.show() and dismiss it in the dialog's button callback.
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]
});
I am using the following piece of code in my PhoneGap app.
function registrationCallBack(button){
if(button == 2) {
window.location.href = "login.html";
}
}
navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");
The order of the buttons is coming properly as "Cancel" and "Ok" in iPhone.
But for Android the order of buttons are reversed. Its coming as "Ok" and then "Cancel".
As a result the button indices are getting changed in the callback method.
All suggestions are welcomed :)
Thanks,
Try using the following solutions:
function showConfirm(message, callback, buttonLabels, title){
//Set default values if not specified by the user.
buttonLabels = buttonLabels || 'OK,Cancel';
title = title || "default title";
//Use Cordova version of the confirm box if possible.
if(navigator.notification && navigator.notification.confirm){
var _callback = function(index){
if(callback){
callback(index == 1);
}
};
navigator.notification.confirm(
message, // message
_callback, // callback
title, // title
buttonLabels // buttonName
);
//Default to the usual JS confirm method.
}else{
invoke(callback, confirm(message));
}
}
And here is how you would use it:
var message = "Would you like to proceed?";
var title = "Important Question";
//The first element of this list is the label for positive
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";
var callback = function(yes){
if(yes){
alert('Proceed');
}else{
alert('Do Not Proceed');
}
};
showConfirm(message, callback, buttonLabels, title);
This is not an Issue. What ever you are getting is native behavior of respective platform. In iOS, "Cancel" button will appear on left side and in Android you will get it on Right side. If the problem is only button index, then you can handle it in your code. But you cannot change the sequence of the buttons on screen.
I haven't tried this in iphone. But have tried this in android. I didn't face any such issues with phonegap 1.4.1. Hence i suggest you to upgrade your phonegap version. Issue you faced might be fixed in their new release. :)
I'm a bit late but I had the same problem, however what I did was change them around so "Cancel" goes where "Ok" is and "Ok" goes where "Cancel" is. That worked for me.