Unity C# Android DatePickerDialog: how to set min and max date?

Hi!

I want to use a date picker on the app and I figured I could just use the native Date Picker that Android provides.

So I google how to show the date picker and in the docs it has an example (http://docs.unity3d.com/ScriptReference/AndroidJavaProxy.html)! Great! However, I want the date picker to only go back as far as 7 years and go up to this current date.

I tried modifying the code in the docs and came up with this:

private static DateTime selectedDate = DateTime.Now;
private static DateTime minDate = DateTime.Now;


TimeSpan span = selectedDate - minDate;
     var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
             activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
                                                                    {
                 AndroidJavaObject datePickerDialog = new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), selectedDate.Year, selectedDate.Month-1, selectedDate.Day);
                 AndroidJavaObject datePicker = datePickerDialog.Call<AndroidJavaObject>("getDatePicker");
                 datePicker.Call("setMinDate", span);
                 datePickerDialog.Call("show");
             }));

however when I trigger this code, nothing happens (I’m building the apk file and loading it straight to the phone, so I don’t see any error messages or anything. Heck, I don’t even know how to build it so that I can!)

How should I go about this?

have you been able to do this?