如何将 Android 选择器列表中的应用程序列为电子邮件客户端? [复制]

Posted

技术标签:

【中文标题】如何将 Android 选择器列表中的应用程序列为电子邮件客户端? [复制]【英文标题】:How to list application in Android chooser list as an email client? [duplicate] 【发布时间】:2018-02-07 08:24:29 【问题描述】:

我正在尝试将我的 android 应用程序添加到选择器列表中作为电子邮件客户端。然而,它并没有出现在 Gmail 和 K-9 应用程序旁边。 为了测试它,我正在尝试从 whatsapp 应用程序聊天的“电子邮件聊天”功能共享聊天数据(因为它只显示电子邮件应用程序)。

我只有一项活动。当我从浏览器共享文本数据时,我的应用程序在选择器列表中,但当我从 Whatsapp 共享电子邮件数据时,我的应用程序不在选择器列表中。我尝试在我的 AndroidManifest.xml 中添加以下意图操作,但它不起作用。

        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="text/*" />
        </intent-filter>

通过调试,我发现 K-9 正在启动如下,

08-30 00:27:28.064 489-2302/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
08-30 00:27:28.064 1685-2620/? I/ActivityManager: START u0 act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) from uid 10158 on display 0
08-30 00:27:28.064 489-24642/? I/Thermal-Lib: Thermal-Lib-Client: Client request sent
08-30 00:27:28.064 753-1089/? I/ThermalEngine: Thermal-Server: Thermal received msg from  override
08-30 00:27:28.077 1685-1997/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@ee526b6 attribute=null, token = android.os.BinderProxy@4b533a5
08-30 00:27:28.177 1685-1749/? I/LaunchCheckinHandler: Displayed android/com.android.internal.app.ChooserActivity,wp,ca,96
08-30 00:27:28.177 1685-1749/? I/ActivityManager: Displayed android/com.android.internal.app.ChooserActivity: +96ms
08-30 00:27:28.244 1685-1845/? D/MotoSensors: ALS 41
08-30 00:27:28.253 1685-1694/? I/art: Background partial concurrent mark sweep GC freed 57795(3MB) AllocSpace objects, 27(1060KB) LOS objects, 30% free, 36MB/52MB, paused 2.148ms total 160.734ms
08-30 00:27:28.306 9905-9979/? D/OpenGLRenderer: endAllActiveAnimators on 0x8ea64500 (aq$a) with handle 0x8ee25d30
08-30 00:27:28.307 1685-2108/? I/WindowManager: Destroying surface Surface(name=PopupWindow:dcadc74) called by com.android.server.wm.WindowStateAnimator.destroySurface:2067 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:896 com.android.server.wm.WindowState.removeLocked:1457 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2546 com.android.server.wm.WindowManagerService.removeWindowLocked:2504 com.android.server.wm.WindowManagerService.removeWindowLocked:2373 com.android.server.wm.WindowManagerService.removeWindow:2364 com.android.server.wm.Session.remove:193 
08-30 00:27:28.553 585-645/? I/SFPerfTracer:      triggers: (rate: 14:1327) (1008781 sw vsyncs) (0 skipped) (42:3589810 vsyncs) (44:4764825)
08-30 00:27:28.707 585-585/? I/SFPerfTracer:      triggers: (rate: 2783:527680) (compose: 1:238) (post: 3:2376) (render: 6:1240) (3:1974551 frames) (4:2171862)
08-30 00:27:28.707 585-585/? D/SFPerfTracer:        layers: (5:12) (DimLayerController/Stack=0 (0xae241400): 1:9571) (StatusBar (0xae243c00): 4:397491) (com.android.systemui.ImageWallpaper (0xacfb7400): 4:264193)* (Sprite (0xae23ec00): 0:863)* (animation background stackId=1 (0xacfb9c00): 0:1482)* (animation background stackId=0 (0xacfd9c00): 0:12)* (NavigationBar (0xacfb6000): 4:252) (com.whatsapp/com.whatsapp.Conversation (0xacfd6000): 4:230) (PopupWindow:e9ad06f (0xacfb8800): 0:44)- (PopupWindow:dcadc74 (0xacfd7400): 0:44)- (Initializing... (0xacfb8800): 0:2)- (android/com.android.internal.app.ChooserActivity (0xacfb8800): 4:28) 
08-30 00:27:29.343 1685-2562/? I/ActivityManager: START u0 act=android.intent.action.SEND_MULTIPLE typ=text/* flg=0xb080001 pkg=com.fsck.k9 cmp=com.fsck.k9/.activity.MessageCompose clip=text/* U:content://com.whatsapp.fileprovider/external/WhatsApp/.Shared/WhatsApp%20Chat%20with%20%E2%80%AA%2B91%2096019%2049744%E2%80%AC.txt (has extras) from uid 10158 on display 0

我还将 type=text/* 放在我的意图过滤器中,但是我的应用没有列出。知道为什么吗?我该怎么做才能列出它?

【问题讨论】:

链接到我的代码以供参考。 github.com/sunilshahu/DataReceiver 你试过这个吗:***.com/a/6796128/1048340? 【参考方案1】:

我直接从 Gmail APK 中提取了这些意图过滤器。

此意图过滤器处理 mailto 链接。

<intent-filter>

    <action
        android:name="android.intent.action.SENDTO" />

    <action
        android:name="android.intent.action.VIEW" />

    <category
        android:name="android.intent.category.DEFAULT" />

    <category
        android:name="android.intent.category.BROWSABLE" />

    <data
        android:scheme="mailto" />
</intent-filter>

这个允许处理通过 NFC 发现的 mailto 意图。

<intent-filter>

    <action
        android:name="android.nfc.action.NDEF_DISCOVERED" />

    <category
        android:name="android.intent.category.DEFAULT" />

    <data
        android:scheme="mailto" />
</intent-filter>

这个允许打开您的应用作为对 SEND 意图和 "Ok Google, note to self" voice command 的响应。

<intent-filter>

    <action
        android:name="android.intent.action.SEND" />

    <category
        android:name="android.intent.category.DEFAULT" />

    <category
        android:name="com.google.android.voicesearch.SELF_NOTE" />

    <data
        android:mimeType="*/*" />
</intent-filter>

这个允许一次send multiple items (represented by Uris)。

<intent-filter>

    <action
        android:name="android.intent.action.SEND_MULTIPLE" />

    <category
        android:name="android.intent.category.DEFAULT" />

    <data
        android:mimeType="*/*" />
</intent-filter>

还有两个特定于 Gmail 域的不相关的,我已经忽略了。

验证自己:

    获取 Gmail APK。 在 Android Studio 中,转到主菜单 > 构建 > 分析 APK... 使用文件选择器查找并打开 Gmail APK。 在 APK Analyzer 中选择 AndroidManifest.xml。

在将 Intent 交付给您的应用后对其进行处理超出了范围。

【讨论】:

【参考方案2】:

试试这个:--我希望它有效

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

【讨论】:

你可以看到我的第二个意图过滤器和你一样。但是用我的替换你的只是为了验证它不起作用。任何其他建议都会有很大帮助。【参考方案3】:

试试这个 reference

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <action android:name="android.intent.action.SENDTO"/>
    <data android:scheme="mailto"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.SEND"/>
    <data android:mimeType="*/*"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.SEND_MULTIPLE"/>
    <data android:mimeType="*/*"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

【讨论】:

以上是关于如何将 Android 选择器列表中的应用程序列为电子邮件客户端? [复制]的主要内容,如果未能解决你的问题,请参考以下文章

简单的 Android 目录选择器 - 如何?

Android ListView 选择器颜色

Android - 如何从电子邮件选择器列表中排除 PayPal?

如何在textview android中显示输入法选择器列表标题和摘要?

如何在 QListWidget 中将项目列为组

同一xml中的选择器、图层列表和形状/位图