queryIntents.size>之后的ActivityNotFoundException 0表示日历应用程序

时间:2018-02-02 16:52:50

标签: android android-intent

我有一个针对日历应用程序的Intent,并且报告了使用activitynotfound的runtimeexception。解决方案是在启动Activity之前添加queryIntents,但它仍然报告相同的错误,并且在新应用程序版本中的if中解析为true。

    Intent intent = new Intent(Intent.ACTION_INSERT)
            .setData(Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, date)
            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, date)
            .putExtra(Events.TITLE, title)
            .putExtra(Events.DESCRIPTION, description)
            .putExtra(Events.EVENT_LOCATION, adress)
            .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
    if(getPackageManager().queryIntentActivities(intent, 0).size() > 0)
        startActivity(intent);
    else
        new AlertDialog.Builder(this)
                .setTitle("Warn")
                .setMessage("No app on device to handle")
                .setPositiveButton("OK", new FinishOnClickListener(this));

并且仍然从startActivity提出错误。

如何正确检查或尝试/捕获异常是唯一的解决方案?

堆栈跟踪:

Caused by: android.content.ActivityNotFoundException: 
  at android.app.Instrumentation.checkStartActivityResult (Instrumentation.java:1793)
  at android.app.Instrumentation.execStartActivity (Instrumentation.java:1491)
  at android.app.Activity.startActivityForResult (Activity.java:3796)
  at android.app.Activity.startActivityForResult (Activity.java:3744)
  at android.app.Activity.startActivity (Activity.java:4067)
  at android.app.Activity.startActivity (Activity.java:4035)
  at br.CalendarLocalActivity.onCreate (CalendarLocalActivity.java:44)

第44行是startActivity。

此外,上面的代码位于活动的onCreate。

0 个答案:

没有答案