谁能指导我如何从android浏览器启动我的android应用程序?


当前回答

是的,Chrome搜索而不是寻找方案。如果你想通过URI方案启动你的应用程序,使用Play商店上的这个很酷的实用程序。它拯救了我的一天:) https://play.google.com/store/apps/details?id=com.naosim.urlschemesender

其他回答

截至2019年6月15日

我所做的是包括所有四种打开url的可能性。

也就是说,有HTTP / HTTPS, 2有WWW前缀,2没有WWW

通过使用这个,我的应用程序现在自动启动,而不需要我选择浏览器和其他选项。

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="https" android:host="example.in" />
    <data android:scheme="https" android:host="www.example.in" />
    <data android:scheme="http" android:host="example.in" />
    <data android:scheme="http" android:host="www.example.in" />

</intent-filter>

使用<intent-filter>和<data>元素。例如,要处理所有到twitter.com的链接,你可以把这个放在AndroidManifest.xml中的<activity>中:

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

然后,当用户在浏览器中单击twitter的链接时,将询问他们使用什么应用程序来完成操作:浏览器还是您的应用程序。

当然,如果你想在你的网站和应用程序之间提供紧密的集成,你可以定义你自己的方案:

<intent-filter>
    <data android:scheme="my.special.scheme" />
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

然后,在你的web应用中,你可以添加如下链接:

<a href="my.special.scheme://other/parameters/here">

当用户点击它时,你的应用程序将自动启动(因为它可能是唯一一个可以处理my.special的应用程序)。scheme://类型的uri)。唯一的缺点是,如果用户没有安装应用程序,他们会得到一个讨厌的错误。我不确定有什么办法能查到。


编辑:为了回答你的问题,你可以使用getIntent(). getdata(),它返回一个Uri对象。然后可以使用Uri。*方法来提取所需的数据。例如,假设用户点击了一个到http://twitter.com/status/1234:的链接

Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"

你可以在Activity的任何地方执行上述操作,但你可能会想在onCreate()中执行。您还可以使用params.size()来获取Uri中路径段的数量。查看javadoc或android开发人员网站,您可以使用其他Uri方法来提取特定的部分。

嘿,我有办法了。我没有将类别设置为“默认”。此外,我使用的主要活动的意图数据。现在我正在使用一个不同的活动的意图数据。谢谢你的帮助。:)

你需要添加一个伪主机名到CALLBACK_URL 'app://'作为URL没有意义,不能被解析。

是的,Chrome搜索而不是寻找方案。如果你想通过URI方案启动你的应用程序,使用Play商店上的这个很酷的实用程序。它拯救了我的一天:) https://play.google.com/store/apps/details?id=com.naosim.urlschemesender