分支io-通过Play商店安装应用后,无RefersParams

时间:2020-10-15 14:55:54

标签: java android android-studio branch branch.io

我有2个问题:

  1. 主要问题是,如果该应用未安装在我的手机(android)上,则分支链接发送我通过Play商店进行安装,但随后在我安装并从那里打开它后,我没有了深度链接数据。

  2. 如果该应用程序已经安装,并且我点击了分支链接,则需要选择通过chrome或通过应用程序打开它, 如果我选择chrome->再也没有深层链接数据。

这是源代码:

MainApp.java

public class MainApp extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

}

@Override public void onStart() {
    super.onStart();
    try {
        Branch.sessionBuilder(this).withCallback(new Branch.BranchReferralInitListener() {
            @Override
            public void onInitFinished(JSONObject referringParams, BranchError error) {
                if (error == null) {

                    // option 3: navigate to page
                    Intent intent = new Intent(MainApp.this, Main2Activity.class);
                    startActivity(intent);
                    

                } else {
                    Log.i("BRANCH SDK", error.getMessage());
                }
            }
        }).withData(this.getIntent().getData()).init();

    }
    catch (Exception e) {
        e.printStackTrace();
    }

}
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    try {
        setIntent(intent);
        // if activity is in foreground (or in backstack but partially visible) launching the same
        // activity will skip onStart, handle this case with reInitSession
        Branch.sessionBuilder(this).withCallback(branchReferralInitListener).reInit();
    }
    catch (Exception ignored) { }

}

private Branch.BranchReferralInitListener branchReferralInitListener = new Branch.BranchReferralInitListener() {
    @Override
    public void onInitFinished(JSONObject linkProperties, BranchError error) {
        // do stuff with deep link data (nav to page, display content, etc)
    }
};

}

Main2Activity.java

公共类Main2Activity扩展了AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

}

@Override public void onStart() {
    super.onStart();
    try{
        // Branch logging for debugging
        Branch.enableLogging();

        // Branch object initialization
        Branch.getAutoInstance(this);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    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"
    android:usesCleartextTraffic="true">

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <activity
        android:name=".MainApp">
        <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="hello" />
            <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 -->
    <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_jeVWU2AYfrIjpJmslgNxZgjeAwcUzcqK" />
    <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
    <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />     <!-- Set to true to use Branch_Test_Key (useful when simulating installs and/or switching between debug and production flavors) -->


    <activity android:name=".MainActivity" />
    <activity android:name=".Main2Activity" >
    <!-- Branch App Links (optional) -->
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" android:host="2rerz.app.link" />
        <!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website.  -->
        <data android:scheme="https" android:host="2rerz-alternate.app.link" />
    </intent-filter>
    </activity>

</application>

CustomApplication.java

    import android.app.Application;

import io.branch.referral.Branch;

public class CustomApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // Branch logging for debugging
        //Branch.enableLogging();
        // Branch object initialization
        Branch.getAutoInstance(this);
    }
}

1 个答案:

答案 0 :(得分:0)

正确的Manifest.xml文件应如下所示-

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id" />

<activity
    android:name=".MainApp">
    <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="hello" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>

<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="2rerz.app.link" />
    <!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website.  -->
    <data android:scheme="https" android:host="2rerz-alternate.app.link" />
</intent-filter>
</activity>

<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_jeVWU2AYfrIjpJmslgNxZgjeAwcUzcqK" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />     <!-- Set to true to use Branch_Test_Key (useful when simulating installs and/or switching between debug and production flavors) -->


<activity android:name=".MainActivity" />
<activity android:name=".Main2Activity" >
</activity>

此外,请确保使用正确的API密钥以及所使用的链接。如果是实时链接,则使用实时API密钥,反之亦然。

相关问题