Skip to content

Commit 6687fb1

Browse files
committed
Added delayed init
1 parent 61b410d commit 6687fb1

39 files changed

+1138
-0
lines changed

Linking-Testbeds/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
plugins {
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.jetbrainsKotlinAndroid)
4+
}
5+
6+
android {
7+
namespace = "io.branch.delayedinittest"
8+
compileSdk = 35
9+
10+
defaultConfig {
11+
applicationId = "io.branch.delayedinittest"
12+
minSdk = 26
13+
targetSdk = 35
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary = true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
isMinifyEnabled = false
26+
proguardFiles(
27+
getDefaultProguardFile("proguard-android-optimize.txt"),
28+
"proguard-rules.pro"
29+
)
30+
}
31+
}
32+
compileOptions {
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
35+
}
36+
kotlinOptions {
37+
jvmTarget = "1.8"
38+
}
39+
buildFeatures {
40+
compose = true
41+
}
42+
composeOptions {
43+
kotlinCompilerExtensionVersion = "1.5.1"
44+
}
45+
packaging {
46+
resources {
47+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
48+
}
49+
}
50+
}
51+
52+
dependencies {
53+
54+
implementation(libs.androidx.core.ktx)
55+
implementation(libs.androidx.lifecycle.runtime.ktx)
56+
implementation(libs.androidx.activity.compose)
57+
implementation(platform(libs.androidx.compose.bom))
58+
implementation(libs.androidx.ui)
59+
implementation(libs.androidx.ui.graphics)
60+
implementation(libs.androidx.ui.tooling.preview)
61+
implementation(libs.androidx.material3)
62+
testImplementation(libs.junit)
63+
androidTestImplementation(libs.androidx.junit)
64+
androidTestImplementation(libs.androidx.espresso.core)
65+
androidTestImplementation(platform(libs.androidx.compose.bom))
66+
androidTestImplementation(libs.androidx.ui.test.junit4)
67+
debugImplementation(libs.androidx.ui.tooling)
68+
debugImplementation(libs.androidx.ui.test.manifest)
69+
70+
implementation("io.branch.sdk.android:library:5.15.0")
71+
implementation("com.google.android.gms:play-services-ads-identifier:18.0.1")
72+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.branch.delayedinittest
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("io.branch.delayedinittest", appContext.packageName)
23+
}
24+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
7+
8+
<application
9+
android:allowBackup="true"
10+
android:dataExtractionRules="@xml/data_extraction_rules"
11+
android:fullBackupContent="@xml/backup_rules"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:roundIcon="@mipmap/ic_launcher_round"
15+
android:supportsRtl="true"
16+
android:theme="@style/Theme.DelayedInitTest"
17+
tools:targetApi="31"
18+
android:name="io.branch.delayedinittest.DelayedInitTestApplication"
19+
>
20+
<activity
21+
android:name=".MainActivity"
22+
android:exported="true"
23+
android:label="@string/app_name"
24+
android:theme="@style/Theme.DelayedInitTest">
25+
<intent-filter>
26+
<action android:name="android.intent.action.MAIN" />
27+
28+
<category android:name="android.intent.category.LAUNCHER" />
29+
</intent-filter>
30+
31+
<!-- Non AppLink example -->
32+
<intent-filter>
33+
<data android:scheme="branchtest" />
34+
<action android:name="android.intent.action.VIEW" />
35+
36+
<category android:name="android.intent.category.DEFAULT" />
37+
<category android:name="android.intent.category.BROWSABLE" />
38+
</intent-filter>
39+
40+
<!-- AppLink example -->
41+
42+
<!-- Custom App link example. You can create your custom app link domain on Branch dash board-->
43+
<intent-filter android:autoVerify="true">
44+
<action android:name="android.intent.action.VIEW" />
45+
46+
<category android:name="android.intent.category.DEFAULT" />
47+
<category android:name="android.intent.category.BROWSABLE" />
48+
49+
<data android:scheme="https" />
50+
<data android:host="bnc.lt" />
51+
<data android:pathPrefix="/xhsd" />
52+
</intent-filter>
53+
<intent-filter>
54+
<action android:name="android.intent.action.VIEW" />
55+
56+
<category android:name="android.intent.category.DEFAULT" />
57+
<category android:name="android.intent.category.BROWSABLE" />
58+
59+
<data android:scheme="https" />
60+
<data android:host="bnc.lt" />
61+
<data android:pathPrefix="/Ojqd" />
62+
</intent-filter>
63+
<intent-filter>
64+
<action android:name="android.intent.action.VIEW" />
65+
66+
<category android:name="android.intent.category.DEFAULT" />
67+
<category android:name="android.intent.category.BROWSABLE" />
68+
69+
<data android:scheme="https" />
70+
<data android:host="bnc.lt" />
71+
<data android:pathPrefix="/xhsd" />
72+
</intent-filter>
73+
<intent-filter>
74+
<action android:name="android.intent.action.VIEW" />
75+
76+
<category android:name="android.intent.category.DEFAULT" />
77+
<category android:name="android.intent.category.BROWSABLE" />
78+
79+
<data android:scheme="https" />
80+
<data android:host="bnc.lt" />
81+
<data android:pathPrefix="/Ojqd" />
82+
</intent-filter>
83+
<intent-filter>
84+
<action android:name="android.intent.action.VIEW" />
85+
86+
<category android:name="android.intent.category.DEFAULT" />
87+
<category android:name="android.intent.category.BROWSABLE" />
88+
89+
<data android:scheme="https" />
90+
<data android:host="bnctestbed.app.link" />
91+
</intent-filter>
92+
<intent-filter>
93+
<action android:name="android.intent.action.VIEW" />
94+
95+
<category android:name="android.intent.category.DEFAULT" />
96+
<category android:name="android.intent.category.BROWSABLE" />
97+
98+
<data android:scheme="https" />
99+
<data android:host="bnctestbed-alternate.test-app.link" />
100+
</intent-filter>
101+
<intent-filter>
102+
<action android:name="android.intent.action.VIEW" />
103+
104+
<category android:name="android.intent.category.DEFAULT" />
105+
<category android:name="android.intent.category.BROWSABLE" />
106+
107+
<data android:scheme="https" />
108+
<data android:host="bnctestbed-alternate.app.link" />
109+
</intent-filter>
110+
<intent-filter>
111+
<action android:name="android.intent.action.VIEW" />
112+
113+
<category android:name="android.intent.category.DEFAULT" />
114+
<category android:name="android.intent.category.BROWSABLE" />
115+
116+
<data android:scheme="https" />
117+
<data android:host="bnctestbed-alternate.app.link" />
118+
</intent-filter>
119+
</activity>
120+
121+
<!-- Branch init -->
122+
<!-- REPLACE `BranchKey` with the value from your Branch Dashboard -->
123+
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB" />
124+
<!-- REPLACE `BranchKey.test` with the value from your Branch Dashboard -->
125+
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hdcBLUy1xZ1JD0tKg7qrLcgirFmPPVJc" />
126+
<!-- Set to `true` to use `BranchKey.test` -->
127+
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
128+
129+
</application>
130+
131+
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.branch.delayedinittest
2+
3+
import android.app.Application
4+
import io.branch.referral.Branch
5+
import io.branch.referral.BranchLogger.BranchLogLevel
6+
7+
class DelayedInitTestApplication: Application() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
12+
Branch.expectDelayedSessionInitialization(true)
13+
14+
Branch.enableLogging(BranchLogLevel.VERBOSE)
15+
16+
Branch.getAutoInstance(this)
17+
}
18+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package io.branch.delayedinittest
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
import androidx.activity.ComponentActivity
6+
import androidx.activity.compose.setContent
7+
import androidx.compose.foundation.layout.*
8+
import androidx.compose.material3.*
9+
import androidx.compose.runtime.*
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.tooling.preview.Preview
12+
import androidx.compose.ui.unit.dp
13+
import io.branch.delayedinittest.ui.theme.DelayedInitTestTheme
14+
import io.branch.referral.Branch
15+
16+
class MainActivity : ComponentActivity() {
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setContent {
20+
DelayedInitTestTheme {
21+
Surface(
22+
modifier = Modifier.fillMaxSize(),
23+
color = MaterialTheme.colorScheme.background
24+
) {
25+
DelayedBranchInitUI { initializeBranch() }
26+
}
27+
}
28+
}
29+
}
30+
31+
private fun initializeBranch() {
32+
// Initialize the Branch SDK
33+
Branch.sessionBuilder(this).withCallback { branchUniversalObject, linkProperties, error ->
34+
if (error != null) {
35+
Log.e("BranchSDK_Tester", "branch init failed. Caused by -" + error.message)
36+
} else {
37+
Log.i("BranchSDK_Tester", "branch init complete!")
38+
if (branchUniversalObject != null) {
39+
Log.i("BranchSDK_Tester", "title " + branchUniversalObject.title)
40+
Log.i("BranchSDK_Tester", "CanonicalIdentifier " + branchUniversalObject.canonicalIdentifier)
41+
Log.i("BranchSDK_Tester", "metadata " + branchUniversalObject.contentMetadata.convertToJson())
42+
}
43+
if (linkProperties != null) {
44+
Log.i("BranchSDK_Tester", "Channel " + linkProperties.channel)
45+
Log.i("BranchSDK_Tester", "control params " + linkProperties.controlParams)
46+
}
47+
}
48+
}.withData(this.intent.data).init()
49+
}
50+
51+
// fun onNewIntent(intent: Intent?) {
52+
// if (intent != null) {
53+
// super.onNewIntent(intent)
54+
// }
55+
// this.setIntent(intent);
56+
// if (intent != null && intent.hasExtra("branch_force_new_session") && intent.getBooleanExtra("branch_force_new_session",false)) {
57+
// Branch.sessionBuilder(this).withCallback { referringParams, error ->
58+
// if (error != null) {
59+
// Log.e("BranchSDK_Tester", error.message)
60+
// } else if (referringParams != null) {
61+
// Log.i("BranchSDK_Tester", referringParams.toString())
62+
// }
63+
// }.reInit()
64+
// }
65+
// }
66+
67+
}
68+
69+
@Composable
70+
fun DelayedBranchInitUI(onInitClick: () -> Unit) {
71+
var isInitialized by remember { mutableStateOf(false) }
72+
73+
Column(
74+
modifier = Modifier
75+
.fillMaxSize()
76+
.padding(16.dp),
77+
verticalArrangement = Arrangement.Center,
78+
horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally
79+
) {
80+
if (isInitialized) {
81+
Text("Branch SDK Initialized!")
82+
} else {
83+
Button(onClick = {
84+
onInitClick()
85+
isInitialized = true
86+
}) {
87+
Text("Initialize Branch SDK")
88+
}
89+
}
90+
}
91+
}
92+
93+
@Preview(showBackground = true)
94+
@Composable
95+
fun DelayedBranchInitPreview() {
96+
DelayedInitTestTheme {
97+
DelayedBranchInitUI {}
98+
}
99+
}

0 commit comments

Comments
 (0)