我一直在尝试从电子邮件上的链接或一些社交网站上的帖子启动应用程序。问题是,在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浏览),并在没有应用程序的装置上显示网页。
创建一个指向您控制的网站(如amazons3上的静态网站)的真实链接(http:),使用该网站上的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>