I tried to use PutExtra & GetIntExtra, But the notification id is always overwritten by the last notification, All the notification value is the same. Please tell me how to solve it,
Thanks in advance!
Intent actionIntent = new Intent(this, typeof(ConfirmActivity));
actionIntent.PutExtra("NOTIFY_ID", 1);
PendingIntent actionPendingIntent = PendingIntent.GetActivity(this, 0, actionIntent, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent)
.Build();
var notification = new NotificationCompat.Builder(this)
.SetContentTitle("1111")
.SetContentText("1111111111111111111111")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action)).Build();
var manager = NotificationManagerCompat.From(this);
manager.Notify(1, notification);
Intent actionIntent2 = new Intent(this, typeof(ConfirmActivity));
actionIntent2.PutExtra("NOTIFY_ID", 2);
PendingIntent actionPendingIntent2 = PendingIntent.GetActivity(this, 0, actionIntent2, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent2)
.Build();
var notification2 = new NotificationCompat.Builder(this)
.SetContentTitle("2222")
.SetContentText("22222222222222222222")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action2)).Build();
manager.Notify(2, notification2);
=================================
[Activity(Label = "ConfirmActivity")]
public class ConfirmActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Confirm);
Intent intent = this.Intent;
int NOTIFY_ID = intent.GetIntExtra("NOTIFY_ID", 0); //always 2
}
}
You may want to check on this thread. It suggested to pass a Bundle along with PendingIntent to the next Activity.
Bundle bundle = new Bundle();
bundle.putString("Any String");
NotificationManager notifManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE);
int uniqueInteger = //create a unique Integer
int icon = R.drawable.ic_launcher;
NotificationCompat2.Builder mNotification = new NotificationCompat2.Builder(this).setSmallIcon(icon)
.setContentTitle(contentTitle).setContentIntent(getPendingIntent(bundle, uniqueInteger));
mNotification.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mNotification.setAutoCancel(true);
notifManager.notify(uniqueInteger, mNotification.build());
Here are some related SO posts which might help:
How to check which notification id is clicked?
Getting data from clicked notification in android
Get the PendingIntent event when notification is clicked
Related
We are using communication notification to update notification icon, but for us it's not working for xamarin project.
var intent = new INSendMessageIntent(null,INOutgoingMessageType.Text,
"Message content",
null,
"unique-conversation-id-1",
null,
sender,null);
// Use the intent to initialize the interaction.
var interaction = new INInteraction(intent: intent, response: null);
interaction.Direction = INInteractionDirection.Incoming;
interaction.DonateInteraction((error) =>
{
// ...
});
NSError error1 = null;
var content = request.Content;
var updatedContent = content.Update(intent, out error1);
contentHandler(updatedContent);
So, I am attempting to get a GUI working for a programming project. This involved changing it from a simple scanning function to converting the userinput from the text field using parse Double. The program was able to function, but once I made the change it throws the exception in the title and terminates the program every time I run it. Yes, I do have a main method.
Here is the relevant code:
public class TaxProject extends Application implements
EventHandler<ActionEvent>
{
private Stage primaryStage;
private Button button;
public void start(Stage primaryStage)
{
Scanner input = new Scanner(System.in);
TaxInput t1 = new TaxInput();
StateTax s1 = new StateTax(); //Declaring Classes
FedTax f1 = new FedTax();
GridPane pane = new GridPane();
pane.setPadding(new Insets(10, 10, 10, 10));
pane.setVgap(8);
pane.setHgap(10);
TextField tfHrlyWage = new TextField();
TextField tfHrsPerWeek = new TextField();
TextField tfMaritalStatus = new TextField();
TextField tfIncome = new TextField();
Button btCalculate = new Button("Calculate");
pane.add(new Label("Hourly Wage: "), 0, 0);
pane.add(new Label("Hours Per Week: "), 0, 1);
pane.add(new Label("Married or Single? "), 0, 2);
pane.add(btCalculate, 0, 3);
pane.add(tfHrlyWage, 1, 0);
pane.add(tfHrsPerWeek, 1, 1);
pane.add(tfMaritalStatus, 1, 2);
pane.add(tfIncome, 1, 0);
tfHrlyWage.setPrefColumnCount(4);
tfHrsPerWeek.setPrefColumnCount(3);
tfMaritalStatus.setPrefColumnCount(7);
tfIncome.setPrefColumnCount(7);
Scene scene = new Scene(pane, 250,150);
primaryStage.setTitle("Tax Calculator");
primaryStage.setScene(scene);
primaryStage.show();
String MaritalStatus; //Used for deciding federal income tax brackets
//System.out.println("Please Enter your Hourly Wage:");
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText()); //HourlyWage Input
//System.out.println("Please Enter the hours you work per week:");
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
MaritalStatus = tfMaritalStatus.getText();
btCalculate.setOnAction(e -> System.out.println("Your Yearly Income After Federal and State Income Taxes is $" + f1.YearlyTakeHome));
The start method is simply setting up the GUI. Nothing makes the code wait for user input the way a console program with a scanner would.
JavaFX is event based and you should find some event/property to add a event handler/listener to and react on events/changes.
This could be a listener to the text property of the TextFields, if you want to automatically update the result on a change of the text field content
//t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
//t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
InvalidationListener listener = o -> {
try {
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
// TODO: some output???
} catch (NumberFormatException ex) {
// TODO: output error message???
}
};
tfHrlyWage.textProperty().addListener(listener);
tfHrsPerWeek.textProperty().addListener(listener);
or from the listener to the button event handler:
//t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
//t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
btCalculate.setOnAction(e -> {
try {
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
// TODO: use properties for some calculations???
} catch (NumberFormatException ex) {
// TODO: display error message???
}
System.out.println("Your Yearly Income After Federal and State Income Taxes is $" + f1.YearlyTakeHome);
});
I am using mvvmCross 5.3 and Xamarin 6.3 and need help to access data passed by notification.
When I get a notification, I'm getting a standard JSON that is sent by Apple. I also receive one more parameter that I'll use to point to some screen in my application.
In my AppDelegate, I have the following code:
public override bool FinishedLaunching(UIApplication application, NSDictionary options)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
var setup = new Setup(this, Window);
setup.Initialize();
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
Window.MakeKeyAndVisible();
//Push Notifications
if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
return ApplicationDelegate.SharedInstance.FinishedLaunching(application, options);
}
In the parameter options, I know that I get the information I need. I do not know how to access this information in my code.
2017-10-26 11:39:28.680 App.IOs[6733:2676232]
{
UIApplicationLaunchOptionsRemoteNotificationKey =
{
aps =
{
alert =
{
body = "Message";
title = "Title";
};
};
idOrder = 254;
};
}
You can create a method like this and call it in the iOS methods that receive the notifications in AppDelegate:
private void HandleReceivedNotification(NSDictionary userInfo = null)
{
if (userInfo != null)
{
var apsDictionary = userInfo["aps"] as NSDictionary;
var alertDictionary = apsDictionary["alert"] as NSDictionary;
var body = alertDictionary["body"].ToString();
var idOrder = userInfo["idOrder "].ToString();
}
}
But don't forget to include a try/catch and check if any variable is null.
First i create a tile with this code:
private void btnIconicTile_Click(object sender, RoutedEventArgs e)
{
IconicTileData oIcontile = new IconicTileData();
oIcontile.Title = "Hello Iconic Tile!!";
oIcontile.Count = 7;
oIcontile.IconImage = new Uri("Assets/Tiles/Iconic/202x202.png", UriKind.Relative);
oIcontile.SmallIconImage = new Uri("Assets/Tiles/Iconic/110x110.png", UriKind.Relative);
oIcontile.WideContent1 = "windows phone 8 Live tile";
oIcontile.WideContent2 = "Icon tile";
oIcontile.WideContent3 = "All about Live tiles By WmDev";
oIcontile.BackgroundColor = System.Windows.Media.Colors.Black;
// find the tile object for the application tile that using "Iconic" contains string in it.
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Iconic".ToString()));
if (TileToFind != null && TileToFind.NavigationUri.ToString().Contains("Iconic"))
{
TileToFind.Delete();
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
else
{
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);//
}
}
Now i want that the created tile in the homescreen links to an app (Uri Scheme?) like this on for ex:
await Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"));
How i can modify the "link" of that recently created tile?
Yes i need too.
Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"))
homescreen
I am adding a reminder to a calendar entry. i am using this piece of code,
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, _calId);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, "Test Event");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, "This is an event created for demo app");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(DateTime.Today, DateTime.Now));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(DateTime.Today.AddDays(1), DateTime.Now));
eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, true);
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "Local");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "Local");
var eventUri = ContentResolver.Insert(CalendarContract.Events.ContentUri,
eventValues);
long eventID = long.Parse(eventUri.LastPathSegment);
string reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
// reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.CalendarId, _calId);
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, eventID);
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, RemindersMethod.Alert.ToString());
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, 5);
Android.Net.Uri url = Android.Net.Uri.Parse(reminderUriString);
var reminderUri = ContentResolver.Insert(url, reminderValues);
this doesnt give any exception but does not add the reminder either. what is wrong? How do i add reminder?i do have write permission. I am able to add calendar events but not able to add reminders
RemindersMethod is an enum, so you need to cast it to an int.
So change your code for adding Reminder method to:
remindersValues.Put(
CalendarContract.Reminders.InterfaceConsts.Method,
(int) RemindersMethod.Alert
);