我使用一个 Activity
创建了简单的应用程序, list 如下:
<?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
中,我粘贴了仪表板实时 key 。
然后在我的应用程序中添加了以下内容:
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 的工作原理?
最佳答案
这里的问题是您在网页上放置的链接。
使用 Branch 时,您不构建自己的 Intent 字符串:您使用 Branch 链接。您可以从应用程序的“分支”仪表板的“营销”页面上创建“分支”链接(此处: https://dashboard.branch.io/marketing );通过使用 Branch SDK 调用在您的移动应用程序中;或者通过将查询参数附加到您的分支链接域(可以在仪表板上的“链接设置”页面底部找到,此处: https://dashboard.branch.io/settings/link )。各种方法的完整描述可以在这里找到:https://dev.branch.io/getting-started/creating-links/overview/
关于您放置在网页上的特定 Intent 字符串,您尚未定义任何 Intent 过滤器或 Activity 来处理“mysite.com”URI 路径。用“open”替换此 URI 路径可能会使链接正常工作,但我建议创建 Branch 链接作为此处的最佳方法。
关于Android Branch IO 深度链接无法打开我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292615/