【发布时间】:2015-08-21 16:04:40
【问题描述】:
我需要一种在电子邮件中包含链接的方法,该链接可以打开移动应用程序或将用户重定向到网站,具体取决于是否安装了移动应用程序。我需要一个适用于 Android 和 IOS 的解决方案,是否有一套关于如何实现这一点的实践?
谢谢!
【问题讨论】:
标签: android ios mobile-application
我需要一种在电子邮件中包含链接的方法,该链接可以打开移动应用程序或将用户重定向到网站,具体取决于是否安装了移动应用程序。我需要一个适用于 Android 和 IOS 的解决方案,是否有一套关于如何实现这一点的实践?
谢谢!
【问题讨论】:
标签: android ios mobile-application
我认为你需要一个组合的答案。
对于 iOS,您可以将 http:// 替换为 itms:// 或 itms-apps:// 以避免重定向。
How to link to apps on the app store
对于 Android,我认为您需要查看 Mainfest 文件的 <intent-filter> 元素。具体来说,请查看<data> 子元素的文档。
【讨论】:
在 Android 上,您需要通过 Intent Filter 来处理:
<activity
android:name="com.permutassep.IntentEvaluator"
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="your/url"
android:scheme="http" />
<data
android:host="your/url"
android:scheme="https" />
</intent-filter>
</activity>
你需要处理意图数据的类应该是这样的:
public class IntentEvaluator extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = null;
if(getIntent() != null && getIntent().getData() != null){
// Do whatever you want with the Intent data.
}
}
}
【讨论】: