-
Notifications
You must be signed in to change notification settings - Fork 398
/
MainActivity.kt
159 lines (145 loc) · 5.62 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.google.firebase.quickstart.dynamiclinks.kotlin
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.appinvite.AppInviteReferral
import com.google.firebase.appinvite.FirebaseAppInvite
import com.google.firebase.dynamiclinks.ShortDynamicLink
import com.google.firebase.dynamiclinks.ktx.androidParameters
import com.google.firebase.dynamiclinks.ktx.dynamicLink
import com.google.firebase.dynamiclinks.ktx.dynamicLinks
import com.google.firebase.dynamiclinks.ktx.googleAnalyticsParameters
import com.google.firebase.dynamiclinks.ktx.iosParameters
import com.google.firebase.dynamiclinks.ktx.itunesConnectAnalyticsParameters
import com.google.firebase.dynamiclinks.ktx.shortLinkAsync
import com.google.firebase.dynamiclinks.ktx.socialMetaTagParameters
import com.google.firebase.ktx.Firebase
import com.google.firebase.quickstart.dynamiclinks.R
abstract class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun createDynamicLink_Basic() {
// [START create_link_basic]
val dynamicLink = Firebase.dynamicLinks.dynamicLink {
link = Uri.parse("https://www.example.com/")
domainUriPrefix = "https://example.page.link"
// Open links with this app on Android
androidParameters { }
// Open links with com.example.ios on iOS
iosParameters("com.example.ios") { }
}
val dynamicLinkUri = dynamicLink.uri
// [END create_link_basic]
}
fun createDynamicLink_Advanced() {
// [START create_link_advanced]
val dynamicLink = Firebase.dynamicLinks.dynamicLink { // or Firebase.dynamicLinks.shortLinkAsync
link = Uri.parse("https://www.example.com/")
domainUriPrefix = "https://example.page.link"
androidParameters("com.example.android") {
minimumVersion = 125
}
iosParameters("com.example.ios") {
appStoreId = "123456789"
minimumVersion = "1.0.1"
}
googleAnalyticsParameters {
source = "orkut"
medium = "social"
campaign = "example-promo"
}
itunesConnectAnalyticsParameters {
providerToken = "123456"
campaignToken = "example-promo"
}
socialMetaTagParameters {
title = "Example of a Dynamic Link"
description = "This link works whether the app is installed or not!"
}
}
// [END create_link_advanced]
}
fun createShortLink() {
// [START create_short_link]
val shortLinkTask = Firebase.dynamicLinks.shortLinkAsync {
link = Uri.parse("https://www.example.com/")
domainUriPrefix = "https://example.page.link"
// Set parameters
// ...
}.addOnSuccessListener { result ->
// Short link created
val shortLink = result.shortLink
val flowchartLink = result.previewLink
}.addOnFailureListener {
// Error
// ...
}
// [END create_short_link]
}
fun shortenLongLink() {
// [START shorten_long_link]
val shortLinkTask = Firebase.dynamicLinks.shortLinkAsync {
longLink = Uri.parse("https://example.page.link/?link=" +
"https://www.example.com/&apn=com.example.android&ibn=com.example.ios")
}.addOnSuccessListener { result ->
// Short link created
val shortLink = result.shortLink
val flowchartLink = result.previewLink
}.addOnFailureListener {
// Error
// ...
}
// [END shorten_long_link]
}
fun buildShortSuffix() {
// [START ddl_short_suffix]
val shortLinkTask = Firebase.dynamicLinks.shortLinkAsync(ShortDynamicLink.Suffix.SHORT) {
// Set parameters
// ...
}
// [END ddl_short_suffix]
}
fun shareLink(myDynamicLink: Uri) {
// [START ddl_share_link]
val sendIntent = Intent()
val msg = "Hey, check this out: $myDynamicLink"
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_TEXT, msg)
sendIntent.type = "text/plain"
startActivity(sendIntent)
// [END ddl_share_link]
}
fun getInvitation() {
// [START ddl_get_invitation]
Firebase.dynamicLinks
.getDynamicLink(intent)
.addOnCompleteListener { task ->
if (!task.isSuccessful) {
// Handle error
// ...
}
val invite = FirebaseAppInvite.getInvitation(task.result)
if (invite != null) {
// Handle invite
// ...
}
}
// [END ddl_get_invitation]
}
fun getDeepLink() {
// [START ddl_get_deep_link]
val link = AppInviteReferral.getDeepLink(intent)
// [END ddl_get_deep_link]
}
fun onboardingShare(dl: ShortDynamicLink) {
// [START ddl_onboarding_share]
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, "Try this amazing app: " + dl.shortLink)
startActivity(Intent.createChooser(intent, "Share using"))
// [END ddl_onboarding_share]
}
}