【问题标题】:Android: How to send an ics File to apps on the PhoneAndroid:如何将 ics 文件发送到手机上的应用程序
【发布时间】:2017-10-31 09:14:25
【问题描述】:

我正在我的活动中创建一个 .ics 文件。我想将创建的 .ics 文件发送到手机上的日历应用程序,以便该应用程序可以导入事件。

这是我的 Intent 代码:

`Intent intent = new Intent(Intent.ACTION_SEND);
        intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(icsfile));
        startActivity(Intent.createChooser(intent, "How do you want to share?"));`    

很遗憾,选择器中没有显示日历应用。

【问题讨论】:

    标签: java android calendar icalendar android-implicit-intent


    【解决方案1】:

    至少,Google 日历不支持回复ACTION_SEND

    那么,试试吧:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(icsfile), "application/ics");
    startActivity(intent);
    

    (最终,改用FileProvider 而不是Uri.fromFile(),因为对于targetSdkVersion 为23 或更高的应用,这不适用于Android 7.0+)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 2013-05-22
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 2016-11-17
      • 2017-07-04
      相关资源
      最近更新 更多