I've been looking for a way to show an offline (not pushed from a server) toast notification on WP7 for a while now. Any ideas?
If you're trying to show the notification while your application is running, you can use the ToastPrompt from the coding4fun toolkit: http://coding4fun.codeplex.com/
If you want to show the notification while your app isn't running, you can use the ShellToast class from a background agent: http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.shelltoast(v=vs.92).aspx
Within a background task, simply call this method:
public static void makeToast(string toastText)
{
//Make a new toast with content "text"
ShellToast toast = new ShellToast();
toast.Title = "Toast Title: ";
toast.Content = toastText;
//toast.NavigationUri = new Uri();
toast.Show();
}
Related
Hi am developing a Xamarin Forms app. i have implemented local notifications in the app. When the notification has fired, upon clicking the notification it has to navigate to a particular page.
In iOS project in Appdelegate.cs i wrote this method
public async override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
which will fire when the user taps on the notification. here i need to navigate to a page. Here i wrote the below line of code
App.Current.MainPage = new NavigationPage(new FavoritesPage());
It is navigating to the Favorites page but it is just displaying a blank page. OnNavigatedTo method is not calling for the FavoritesViewModel and in the Onnavigated to am calling a method which takes id(this id comes from the notification) as parameter to get a particular favorite
Here two questions
1) How to navigate to a Specific page
2) How to pass a parameter along with the page navigation.
Can someone please help me to solve this issue.
For 1:
You want to push to a new Page, but what you did is replacing the app's MainPage. please try PushAsync. You can subscribe a MessagingCenter in App:
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
MessagingCenter.Subscribe<object, string>(this, "Push", async (sender, favoriteID) =>
{
var favorite = new FavoritesPage();
favorite.FavoriteID = favoriteID;
await (MainPage as NavigationPage).PushAsync(favorite, true);
});
}
This Lambda will fire when you call MessagingCenter.Send<object, string>(this, "Push", "01");
The string 01 here is the ID what I want to push.
For 2:
Before I push to a new page, I define a property called FavoriteID in this page, then I pass the string using method above.
Use MessagingCenter, set ContentPage type or url for MessagingCenter.Send, then MessagingCenter.Subscribe & load
Check my action bar image here(My requirement)i want to display the custom text label button on xamarin.android action bat(material theme),is there any possibility to do that in xamarin.android please suggest ...
static Button notifCount;
static int mNotifCount = 0;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
View count = menu.findItem(R.id.badge).getActionView();
notifCount = (Button) count.findViewById(R.id.notif_count);
notifCount.setText(String.valueOf(mNotifCount));
return super.onCreateOptionsMenu(menu);
}
private void setNotifCount(int count){
mNotifCount = count;
invalidateOptionsMenu();
}
i tried above code converting into xamarin.android but it is showing like..
View count= menu.FindItem(Resource.Id.badge).getActionView ...Error...getActionview is not there in xamarin.
Check out my post about this on the Xamarin Forums. Just did this recently for Push Notifications, though I am not sure if your badge is for Push or Local Notifications. I am using Xamarin Forms so it may be a little different from you but let me know if you have any issues.
Basically, in OnCreateOptionsMenu you make sure you are on your specific page, then inflate your custom badge into the action bar and then add a custom action.
Then in OnPrepareOptionsMenu you can update the badge count. I used the DB to figure out what the new badge value should be.
https://forums.xamarin.com/discussion/comment/183694/#Comment_183694
*Edit: I also found this link recently but have not looked into it much. Might also be helpful.
I am using push sharp to create remote notification.
But I get the notification with out a title and a View/Close buttons.
I am using a code adapted from
Here
Here is how I create my alert
AppleNotificationAlert alert = new AppleNotificationAlert();
alert.ActionLocalizedKey = "View Alert";
alert.Body = message;
alert.AddLocalizedArgs(new object[] { "title", "Test Title"});
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert(alert).WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
I also tried just specifying the Alert body as follows but it does not show View/Close buttons
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert("Alert Body").WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
Your code is right. I just spinned it out and it worked ! In your IOS device settings choose your app and then notifications and then change the notification type from banner to an alert and you will get your custom Buttons and Title!
It´s possible to set an image to be the background of all Pages on my application (for all platforms IOS, Android and WP) ?
Page has a BackgroundImage property, so I can create a base page, set the background and make all my pages extends from it.
I want to know if there is a more appropriate solution, to handle this.
You could use Styles in your App.cs :
public App ()
{
Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(Page)){
Setters = {
new Xamarin.Forms.Setter { Property = Page.BackgroundImageProperty, Value = "back.png"},
}
});
}
much less preferred or advised but for the sake of showing another option you could attach an event handler to your NavigationPages and set the background from there:
yourRootNavigationPage.Pushed+= (sender, e) => e.Page.BackgroundImage = "back.png";
I'm new to creating Silverlight applications. I have inherited a code-base that I've been told is using Prism. Based upon what I've seen in the code-base, this looks to be true. My problem is, I am just trying to open a dialog window and close a dialog window.
To open the dialog window, I'm using the following:
UserControl myDialog = new MyDialog();
IRegion region = myRegionManager.Regions["DIALOG_AREA"];
IRegionManager popupRegionManager = region.Add(myDialog, null, true);
region.Activate(myDialog);
The dialog I have designed appears. It has two buttons: "OK" and "Cancel". When a user clicks on of these dialogs, I want to close the dialog. My problem is, I have no idea how to do this. Because the dialog is not a ChildWindow, I cannot call this.Close(). But, when I change MyDialog to a ChildWindow, it is wrapped in some custom window chrome that i can't figure out how to get rid of.
How do I close a dialog in Prism? Thank you!
Instead of putting in a different region, you should make your ViewModel call a service where you call your dialog window.
public MainPageViewModel(IMainPage view,
ILoginBox loginBox )
: base(view)
{
this.view = view;
this.loginBox = loginBox;
}
public interface ILoginBox
{
void Show();
}
remember to use the IOC container and declare on your ModuleClass:
protected override void RegierTypes()
{
base.Container.RegisterType<ILoginBox , LoginBox>();
}
I hope it helps.
If you are still looking for an example, check:
another Stackoverflow sample