通过电子邮件发送WhatsApp聊天时,如何让我的Android应用程序出现在应用选择器中?

pau*_*eno 6 email android android-intent whatsapp

当我使用WhatsApp中的"电子邮件会话"功能时,我有兴趣让我的应用程序显示在显示的应用程序列表中.

在使用"电子邮件对话"WhatsApp功能登录手机时,我可以看到SEND_MULTIPLEGmail收到的意图:

I/ActivityManager(  859): START u0 {act=android.intent.action.SEND_MULTIPLE typ=text/* flg=0xb080001 pkg=com.google.android.gm cmp=com.google.android.gm/.ComposeActivityGmail (has clip) (has extras)} from uid 10114 on display 0
Run Code Online (Sandbox Code Playgroud)

所以我想我需要为SEND_MULTIPLE我的应用清单中的操作添加一个intent过滤器.

目前我AndroidManifest.xml是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.xxx.xxx" >


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >


    <activity
        android:name=".MyActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <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.SENDTO" />

            <data android:scheme="mailto" />

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

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

            <data android:scheme="mailto" />

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

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

            <data android:mimeType="*/*" />

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

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

            <data android:mimeType="*/*" />

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

    </activity>

</application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

但是,当我通过Android Studio在手机中运行我的应用程序时,在尝试导出WhatsApp会话时它不会显示.相反,它在尝试共享我的画廊的图片时显示在app选择器中.

我在AndroidManifest中遗漏了什么,以防止在通过电子邮件发送我的WhatsApp会话时显示我的应用程序?我需要向操作系统公布其他内容,以使我的应用程序可以出现在应用程序选择器中吗?

我试过安装K-9 Mail应用程序.安装后,在WhatsApp中通过电子邮件发送聊天时,它不会显示在应用选择器中,但在K-9中设置帐户后,它会出现在选择器中.K9是否有可能向操作系统宣布它已准备好发送电子邮件?

谢谢!

Mat*_*ini 13

不幸的是,即使您的清单配置正确,也无法在通过电子邮件发送聊天时在应用选择器中看到您的应用,因为您的应用需要被WhatsApp列入白名单.WhatsApp的应用选择器中仅提供所选的包名称.

例如,我们有一个包名称的应用程序com.example.whatsappemailchat.这AndroidManifest.xml是这样的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.whatsappemailchat" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.whatsappemailchat.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <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.SENDTO"/>
                <data android:scheme="mailto"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <data android:mimeType="*/*"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>
                <data android:mimeType="*/*"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <data android:scheme="mailto"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

这是build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.whatsappemailchat"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

一切都正确配置,我们运行我们的应用程序,但如果我们选择More > Email chat我们的应用程序将不会出现.

现在将我们的更改applicationIdcom.google.android.gm.test(Gmail加密的包名称.test作为后缀以避免与真实Gmail发生冲突)build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.google.android.gm.test"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在运行我们的应用程序,打开WhatsApp,选择一个聊天,选择More > Email chat并神奇地我们的应用程序将在应用程序选择器中,您可以在此屏幕截图中看到:

在此输入图像描述

我可以确认WhatsApp将这些软件包名称列入白名单:

  • com.google.android.gm
  • com.fsck.k9
  • com.boxer.email
  • com.google.android.email

我认为唯一可行的解​​决方案是尝试联系WhatsApp并询问是否可以将您的包名称列入白名单.