【问题标题】:Add custom action to Android Share-Sheet向 Android Share-Sheet 添加自定义操作
【发布时间】:2014-12-16 10:31:43
【问题描述】:

我有一个应用程序,用户应该可以在其中分享一些文本。现在我想为 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);

这看起来有点像:

来源:http://developer.android.com/training/basics/intents/sending.html

但现在我还希望能够在 Share-Service-Picker 对话框中有一个选项来触发我自己的代码中的自定义操作。即我希望用户能够收藏一个条目。因此,除了通过 SMS、电子邮件、FB 等方式分享之外,我还希望在该列表顶部再添加一项,说“添加到收藏夹”(如果可能,包括一个图标)。

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

感谢任何提示!

【问题讨论】:

    标签: android android-intent android-sharing


    【解决方案1】:

    意图过滤器通知系统应用程序组件愿意接受的意图。与您在向其他应用程序发送简单数据课程中使用操作 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>
    

    来自Receiving Simple Data from Other Apps:Update Your Manifest

    【讨论】:

    • 好的,但是每个应用程序都可以使用该操作吗?但我更愿意只添加一个只与我的应用相关的操作...我不能在选择器中添加一些操作或类似的东西?!?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多