从浏览器链接启动 android 应用程序 [英] Launch android application from a browser link

查看:33
本文介绍了从浏览器链接启动 android 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用我自己的方案从浏览器启动我的应用程序时遇到问题.
代码如下:
清单文件:

I have a problem trying to launch my application from the browser using my own scheme.
Code is as follow:
Manifest file:

   <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" 
        android:exported="false">
        <intent-filter>

            <data  android:scheme="allplayer" />

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

HTML 文件:

<html>
<head>
</head>
<body>
<a href="allplayer://site.com">Test link</a>
</body>
</html>

如果我点击链接,我的应用程序将无法启动.我做了很多研究,但找不到答案.
如果我使用 http 更改 allplayer 一切正常.
这个链接,我了解到不建议使用您自己的方案.
这是否意味着您自己的方案行不通?
这里的人正在使用他自己的方案,从他的反馈来看,它似乎是有效的.
我错过了什么吗?

If I click on the link, my application wont start. I did a lot of researches, but couldn't find an answer.
If I change allplayer with http everything works fine.
From this link, I learnt that it is not recommended to use your own schemes.
Does that mean your own schemes wont work?
The person here is using his own scheme, and from his feedback it seems that it is working.
Am I missing something?

推荐答案

我花了 6 个小时才弄清楚问题所在.以某种方式将导出设置为 false 导致了所有问题:android:exported="false".当我将它设置为 true 时,它​​就像一个魅力.

It took me 6 hours to figure out the problem. Somehow setting the exported to false caused all the problem: android:exported="false". When I set it to true, it worked like a charm.

有趣,因为我把它放在那里是为了避免Exported Activity不需要许可警告.将其设置回 true,带回警告,但它现在正在工作.

Funny because I put it there in the first place to avoid the Exported activity does not require permission warning. Setting it back to true, brought back the warning, but it is working now.

解决方案如下.希望它能帮助其他人节省时间.

Solution is below. Hope it will help others save time.

<activity
      android:name=".MainActivity"
      android:label="@string/title_activity_main" 
      android:exported="true">
      <intent-filter>
          <data  android:scheme="allplayer" />
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.BROWSABLE" />
          <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
  </activity>

这篇关于从浏览器链接启动 android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆