【问题标题】:Share Text via intent to application accounts通过意图向应用程序帐户共享文本
【发布时间】:2016-10-19 11:10:59
【问题描述】:

更新AndroidManifest.xml

<activity android:name=".ui.MyActivity" > <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> </activity>

例如,将应用程序添加到文本类型数据的共享列表中。 但是我如何添加选项以从我的应用程序中选择不同的帐户来共享?例如:

【问题讨论】:

    标签: android android-intent share


    【解决方案1】:

    这被称为“Direct Share”,在 Android 6.0 中添加。 基本步骤是:

    • 创建ChooserTargetService的子类

    • that class' onGetChooserTargets() method 中,返回一个ChooserTarget 对象列表,这些对象代表您要让用户共享的特定帐户/标签/任何内容

    • 将服务添加到您的清单中,使用 android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"ChooserTargetService &lt;intent-filter&gt;

    • meta-data 添加到您的ACTION_SEND 活动的&lt;intent-filter&gt;,指向您的ChooserTargetService

    然后,当用户执行调用ACTION_SEND(您的活动是候选活动)的操作时,Android 6.0+ 设备也将显示您的直接共享目标。

    This sample app 演示了这种方法。

    【讨论】:

    • 感谢您的帮助。
    • @IntelliJAmiya 我必须等待至少 5 分钟才能接受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多