0

The below set reminder code is crashing on a particular device. I think its because there is no calendar app installed in it.

How do I check if there is no calender app installed in a device? Calender app can be any, Samsung, google or any other.

I need to check if there is an app to handle a the calender intent. What is the intent filter used by calenders and how to check if there is an app in device to handle that intent.

 public void setReminder(View v)
 {
     Intent intent = new Intent(Intent.ACTION_EDIT);
     intent.setType("vnd.android.cursor.item/event");


     switch (v.getId())
     {
         case R.id.saganReminder:
             GregorianCalendar beginCalDate = new GregorianCalendar(2016, 8,9,19,00);
          //  GregorianCalendar endCalDate = new GregorianCalendar(2016, 8,9,10,00);
             intent.putExtra("title", getResources().getString(R.string.saganReminderName));
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                 intent.putExtra(CalendarContract.Events._ID,1);
                 intent.putExtra(CalendarContract.Events.CALENDAR_ID,1);
                 intent.putExtra(CalendarContract.Events.EVENT_LOCATION, getResources().getString(R.string.sagan_venue_calender));
                 intent.putExtra(CalendarContract.Events.DESCRIPTION, getResources().getString(R.string.CalenderDescriptionSagan));

                 intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false);
                 intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                        beginCalDate.getTimeInMillis());
            //     intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
              //          endCalDate.getTimeInMillis());
                 intent.putExtra(CalendarContract.Events.ACCESS_LEVEL, CalendarContract.Events.ACCESS_PRIVATE);
                 intent.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
                 intent.putExtra(CalendarContract.Events.CALENDAR_COLOR, CalendarContract.Colors.COLOR_KEY);
                 intent.setData(CalendarContract.Events.CONTENT_URI);

            }
            else
            {

                intent.putExtra("beginTime", beginCalDate.getTimeInMillis());
                //intent.putExtra("endTime", endCalDate.getTimeInMillis());

                intent.putExtra("description", getResources().getString(R.string.CalenderDescriptionSagan));
                intent.putExtra("eventLocation", getResources().getString(R.string.sagan_venue_calender));
                intent.putExtra("allDay", true);
            }
            break;
        }

Stack trace for the crash:

java.lang.IllegalStateException: Could not execute method for android:onClick
    at android.support.v7.a.bk.onClick(Unknown Source)
    at android.view.View.performClick(View.java:4470)
    at android.view.View$PerformClick.run(View.java:18599)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5633)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    ... 12 more
 Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content: (has extras) }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1771)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1563)
    at android.app.Activity.startActivityForResult(Activity.java:3505)
    at android.support.v4.b.t.startActivityForResult(Unknown Source)
    at android.support.v4.b.z.startActivityForResult(Unknown Source)
    at android.app.Activity.startActivityForResult(Activity.java:3466)
    at android.support.v4.b.z.startActivityForResult(Unknown Source)
    at android.app.Activity.startActivity(Activity.java:3708)
    at android.app.Activity.startActivity(Activity.java:3676)
Sufian
  • 6,405
  • 16
  • 66
  • 120
user4057066
  • 295
  • 3
  • 14
  • If you have a stacktrace of the crash, you should know why exactly the app crashes. – FD_ Aug 20 '16 at 17:25
  • Related: [question 1](http://stackoverflow.com/questions/4373074/how-to-launch-android-calendar-application-using-intent-froyo) and [question 2](http://stackoverflow.com/questions/23382005/how-to-open-google-calendar-app-from-my-app). – Sufian Oct 06 '16 at 08:56

0 Answers0