【发布时间】:2017-02-17 08:10:25
【问题描述】:
我用一个Activity 创建了一个简单的应用程序,清单如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kz.ant.branchio">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MyApp">
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_XXXXXXXXXXX" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="branchiotestapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
在我的key_live_XXXXXXXXXXX 中,我已经粘贴了我的仪表板实时密钥。
然后在我的应用程序中添加了这个:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Branch.getAutoInstance(this);
}
}
我的MainActivity 有这些代码行:
@Override
protected void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
@Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
我的应用程序 URI 方案是 branchiotestapp://,据我了解,当用户单击此方案的链接时,它应该打开我的应用程序。然后我用这段代码创建了简单的 HTML 网页:
<html>
<head>
<title>Test</title>
</head>
<body>
<a href="branchiotestapp://mysite.com">CLICK</a>
</body>
</html>
当我使用手机浏览器打开此 HTML 并单击此链接时,我的 Android 应用程序即使已安装也无法打开
为什么会这样?我是否误解了 branch.io 的工作原理?
【问题讨论】:
标签: android deep-linking branch.io