将自定义操作添加到 Android Share-Sheet

Geo*_*org 5 android android-intent android-sharing

我有一个应用程序,用户应该能够在其中共享一些文本。现在我想提供 Android 提供的纯文本默认共享选项。我使用以下代码执行此操作:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");

Intent chooser = Intent.createChooser(sendIntent, "Share");
startActivity(chooser);
Run Code Online (Sandbox Code Playgroud)

这看起来有点像这样:

分享对话框来源: http: //developer.android.com/training/basics/intents/sending.html

但现在我还希望能够在共享服务选择器对话框中多一个选项,该选项可以在我自己的代码中触发自定义操作。也就是说,我希望用户能够收藏某个条目。因此,除了通过短信、电子邮件、FB 等方式分享之外,我希望在该列表的顶部再添加一项,注明“添加到收藏夹”(如果可能的话,包括一个图标)。

所以我的问题是这是否可能?!?如果,如何:)

任何提示表示赞赏!

jan*_*sad 0

意图过滤器通知系统应用程序组件愿意接受什么意图。与您在向其他应用程序发送简单数据课程中使用操作 ACTION_SEND 构建意图类似,您创建意图过滤器以便能够通过此操作接收意图。您可以使用 元素在清单中定义意图过滤器。例如,如果您的应用程序处理接收文本内容、任何类型的单个图像或任何类型的多个图像,则您的清单将如下所示:

<activity android:name=".ui.MyActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.SEND_MULTIPLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

从其他应用程序接收简单数据:更新您的清单