【问题标题】:Branch io - No referringParams after app is installed via play store分支 io - 通过 Play 商店安装应用程序后没有引用参数
【发布时间】:2020-10-15 14:55:54
【问题描述】:

我有两个问题:

  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);
    }
}

【问题讨论】:

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


    【解决方案1】:

    正确的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 密钥和您正在使用的链接。如果是 Live Link,则使用 Live API 密钥,反之亦然。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2019-08-25
      • 2019-03-19
      • 2016-09-29
      相关资源
      最近更新 更多