Reputation: 2163
Good day readers, i'm trying to use a method that is ment for android how do i cast the ContentPage to an Activity of android in PCL is it even possible ?
Tried with directives but its also not working
public static void AddEvent(GSDEvents ev, Activity ac)
{
// Id++;
Calendar cal = Calendar.GetInstance(Java.Util.TimeZone.Default, Locale.Default);
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, Id);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, ev.Title);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, ev.Description);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(ev.Year, ev.Month, ev.Day, ev.Hour, ev.Minute));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(ev.Year, ev.Month, ev.Day, ev.Hour, ev.Minute));
eventValues.Put(CalendarContract.Events.InterfaceConsts.AllDay, ev.AllDay ? "1" : "0");
eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, ev.HasAlarm ? "1" : "0");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "GMT+1:00");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "GMT+1:00");
var uriCalendar = ac.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);
ContentValues remindervalues = new ContentValues();
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, ev.ReminderMinute);
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, Id);
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)Android.Provider.RemindersMethod.Alert);
var uriCalendarReminder = ac.ContentResolver.Insert(CalendarContract.Reminders.ContentUri, remindervalues);
}
in my contentpage
#if __ANDROID__
GSDEvents ev = new GSDEvents();
ev.Title = "Test Event";
ev.Description = "Dit is nog een test van de beschrijving";
GSDEvents.AddEvent(ev, __THEPROBLEM HOW CAN I GET THE ACTIVITY);
#endif
does someone know how achieve this i'm working in PCL Hope someone can point me to the right direction.
Kind Regards, Stefan
Upvotes: 0
Views: 733
Reputation: 2163
I did it with DependencyService Thnx guys :) https://developer.xamarin.com/guides/cross-platform/xamarin-forms/dependency-service/
Upvotes: 0
Reputation: 1196
You only have one activity. Main you find it in your Droid app. If you need something specifically up in the activity code it there and initiate it from withen your Xamarin forms Page with an event. Pages don't really correlate to Activities at least not in the way your thinking.
Xamarin Forms is Cross Platform by design thus if you couldn't do it on IOS, WP and Droid you cant do it inside Forms. Since obviously theres no Activities on the other 2 platforms Forms has no concept of an activity withen the PCL.
Im not familiar enough with what a GSDEvent is to help further. But to do what you want your going to have to put an event on your ContentPage. Assign the Code to the event from the Activity in Your Droid Project and fire it inside your PCL when you want it to function.
Alternately you could create a Class in your PCL with an event on it Instantiate it in your droid project and assign the event and then put it into an IOC container that you access from the PCL.
Upvotes: 2