我正在研究android中的深层链接,我发现branch.io提供了深层链接支持。我按照文档记录了所有内容,但仍然是打开自定义链接而不是应用程序。
代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="branch.next.com.newbranchapp">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:name="io.branch.referral.BranchApp""
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Branch URI scheme -->
<intent-filter>
<data android:scheme="branch" 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>
<!-- Branch init -->
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_abFuXvh4EU7Yocf2FB4jJpccAEcz3sZT" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_cbvEXCcXuJ27ojf1yu9sTkaitsoF0v9X" />
<!-- Branch testing (TestMode "true" to simulate fresh installs on dev environment) -->
<meta-data android:name="io.branch.sdk.TestMode" android:value="true" />
<!-- Branch install referrer tracking -->
<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>
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchUniversalReferralInitListener() {
@Override
public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) {
if (error == null) {
Log.i("MyApp","not working");
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
@Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
// application
public class CustomApplication extends Application
{
@Override
public void onCreate()
{
super.onCreate();
Branch.getAutoInstance(this);
}
}
答案 0 :(得分:1)
来自Branch.io的Amruta:
两件事:
您的Application类的名称是&#34; CustomApplication&#34;但在你的Manifest中,我看到你的Application类的名称设置为&#34; android:name =&#34; io.branch.referral.BranchApp&#34;&#34;。我不确定,但我相信这应该会给你的应用程序错误。这应该设置为&#34; .CustomApplication&#34;
我刚看了一下您的分支仪表板。由于您使用应用程序测试版本中的链接进行测试(测试版本中的链接具有类型为#34; .test-app.link&#34;的链接域),因此您应填充Android URL以进行测试链接设置中的版本。你可以在&#39; Live&#39;和&#39;测试&#39;使用仪表板左上角的鳍状肢。