如何从 Android 中的电子邮件 URL 打开已安装的应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26052512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:57:27  来源:igfitidea点击:

How to open an installed app from an email URL in Android?

androidemailurltwitterhtml-email

提问by Roadies

I want to open my app from an email URL, basically like the example shown below for Twitter.com.

我想从电子邮件 URL 打开我的应用程序,基本上就像下面显示的Twitter.com示例一样。

Email with link:

带链接的电子邮件:

Email with link

带链接的电子邮件

Selection to open app or browser:

选择打开应用程序或浏览器:

Select app or browser

选择应用程序或浏览器

After you click on the app choice, the Twitter app opens:

单击应用程序选项后,Twitter 应用程序将打开:

Open Twitter app

打开推特应用

I tried the following code, but it is not working:

我尝试了以下代码,但它不起作用:

<intent-filter>
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <data android:host="www.twitter.com" android:scheme="http"></data>
</intent-filter>

If anyone has a proper answer, please write some examples here.

如果有人有正确的答案,请在此处写一些示例。

回答by hemu

The following code worked for me:

以下代码对我有用:

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

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

    <data
        android:host="www.my.app.com"
        android:path="launch"
        android:scheme="http"></data>
</intent-filter>

With the email link set as http://www.my.app.com/launch.

将电子邮件链接设置为http://www.my.app.com/launch.

Ref: Launching Android Application from link or email

参考:从链接或电子邮件启动 Android 应用程序

回答by Vny Kumar

Ex: Your url will be something like https://roadies.comand you have the intent filter in manifest as below

例如:您的网址将类似于https://roadies.com并且您在清单中有如下意图过滤器

        android:name="com.droid.MainActivity"
        android:label="@string/app_name" >

        <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="roadies.com"
            android:scheme="https" />
    </intent-filter>

    </activity>

回答by Alexandre Bourlier

For me, none of the answers posted here worked. I tried tens of different syntaxes without any success. I was getting a parsing error while building the app via Cordova.

对我来说,这里发布的答案都没有奏效。我尝试了数十种不同的语法,但没有任何成功。通过 Cordova 构建应用程序时出现解析错误。

I finally encountered this answeredwhich led me on the right track.

我终于遇到了这个答案,这让我走上了正轨。

So I created a hook in the PROJECT_ROOT/hooks/after_prepare/folder called 010_add_intent_filters.sh. Here is the content of this hook :

所以我在PROJECT_ROOT/hooks/after_prepare/名为010_add_intent_filters.sh. 这是这个钩子的内容:

!/usr/bin/bash

MANIFEST=./platforms/android/AndroidManifest.xml

grep -q pathPattern $MANIFEST && { print "Manifest already modified. Nothing to do."; exit 0; }

AFTER_LINE='android:name="MainActivity"'
ADDITION='\
  <intent-filter>\
    <action android:name="android.intent.action.VIEW"></action>\
    <category android:name="android.intent.category.DEFAULT"></category>\
    <category android:name="android.intent.category.BROWSABLE"></category>\
    <data android:scheme="https" android:host="google.com" android:pathPattern=".*"></data>\
  </intent-filter>
';

sed -i -e "/${AFTER_LINE}/a${ADDITION}" $MANIFEST

This finally worked. No modification to config.xmlis required if you take the hook path. I hope this helps someone in need.

这终于奏效了。config.xml如果采用钩子路径,则不需要修改 to 。我希望这可以帮助有需要的人。

PS: I am convinced Cordova is a great technology, but I have rarely seen such a badly documented library... How painful it is to work with it is just unbelievable.

PS:我确信 Cordova 是一项伟大的技术,但我很少看到如此糟糕的文档库......使用它是多么痛苦简直令人难以置信。