我一直试图通过电子邮件链接或某些社交网站上的帖子启动应用程序。问题是在android上的某些设备或某些gmail应用程序中没有显示我指定的锚标签或链接。
我为我的活动设置的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:scheme="myappname" />
我正在发送带有此锚标记的电子邮件
myappname://processtobedone/?id=1
它适用于我在华为设备上的电子邮件应用程序,但在设备的默认gmail应用程序中,它没有显示它有链接,并且在某些设备中默认情况下它附加https:作为标签的后缀并启动浏览器。
您可以使用<intent-filter>
来标识您控制的URL,而不是使用自定义方案:
<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="www.this-so-does-not-exist.com"
android:path="/something"
android:scheme="http"/>
</intent-filter>
然后,指向http://www.this-so-does-not-exist.com/something
的链接将在具有您的应用程序的设备上显示您的应用程序(在选择器中,以及Web浏览),并将在没有您的应用程序的设备上显示您的网页。
创建一个真正的链接(http :),你控制的网站,如亚马逊s3上的静态网站,使用该网站上的JavaScript来检测Android用户代理,然后重定向到锚标记的链接。
<activity
android:name=".SplashEmailActivity"
android:screenOrientation="portrait"
android:exported="true"
android:launchMode="singleInstance" android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize" >
<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:scheme="http" android:host="your.domain.name"/>
</intent-filter>
</activity>
要触发设备上的应用程序链接,例如,你的案例myappname://processtobedone/?id=1
,最简单的方法是创建一个基本的html页面文件(名称为deeplink_test.html
)并发送到你的电子邮件,之后打开这封电子邮件并点击html文件,使用Chrome浏览器打开并单击锚点链接。
<html>
<head>
<title>DeepLink Test</title>
<head>
<body>
<a href="myappname://processtobedone/?id=1">run deeplink</a>
<body/>
</html>