Skip to content

Commit 55064d0

Browse files
Merge pull request #2138 from embrace-io/push-notification-example
Add push notification bytecode example
2 parents fc7fab3 + 1687a63 commit 55064d0

7 files changed

Lines changed: 84 additions & 0 deletions

File tree

examples/ExampleApp/app/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ plugins {
55
alias(libs.plugins.embrace)
66
}
77

8+
embrace {
9+
bytecodeInstrumentation {
10+
firebasePushNotificationsEnabled.set(true)
11+
}
12+
}
13+
814
android {
915
namespace = "io.embrace.android.exampleapp"
1016
compileSdk = 35
@@ -60,6 +66,7 @@ dependencies {
6066
implementation(platform(libs.opentelemetry.bom))
6167
implementation(libs.opentelemetry.api)
6268
implementation(libs.opentelemetry.sdk)
69+
implementation(libs.firebase.messaging)
6370

6471
// uncomment to enable debugging through source contained in those modules
6572
// implementation(libs.embrace.android.api)
@@ -68,6 +75,7 @@ dependencies {
6875
// implementation(libs.embrace.android.features)
6976
// implementation(libs.embrace.android.payload)
7077
// implementation(libs.embrace.android.delivery)
78+
implementation(libs.embrace.android.fcm)
7179

7280
testImplementation(libs.junit)
7381
androidTestImplementation(libs.androidx.junit)

examples/ExampleApp/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<activity
3838
android:name=".ui.examples.bytecode.BytecodeOkHttpActivity"
3939
android:theme="@style/Theme.ExampleApp" />
40+
<activity
41+
android:name=".ui.examples.bytecode.BytecodeFcmPushNotificationActivity"
42+
android:theme="@style/Theme.ExampleApp" />
43+
44+
<service android:name=".ui.examples.bytecode.ExamplePushNotificationService"
45+
/>
4046
</application>
4147

4248
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.embrace.android.exampleapp.ui.examples.bytecode
2+
3+
import android.os.Bundle
4+
import android.view.View
5+
import androidx.activity.ComponentActivity
6+
import com.google.firebase.messaging.RemoteMessage
7+
import io.embrace.android.exampleapp.R
8+
9+
class BytecodeFcmPushNotificationActivity : ComponentActivity() {
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.activity_bytecode_fcm_push_notification)
14+
15+
findViewById<View>(R.id.btn_bytecode_fcm_push_notification).setOnClickListener {
16+
val msg = RemoteMessage.Builder("my-id")
17+
.setMessageId("my-message-id")
18+
.setMessageType("my-message-type")
19+
.setData(mapOf("key" to "value"))
20+
.build()
21+
ExamplePushNotificationService().onMessageReceived(msg)
22+
}
23+
}
24+
}

examples/ExampleApp/app/src/main/kotlin/io/embrace/android/exampleapp/ui/examples/bytecode/BytecodeInstrumentationExample.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private val items = listOf(
1515
BytecodeSample("OnClick/OnLongClick", BytecodeViewClickActivity::class),
1616
BytecodeSample("WebView", BytecodeWebViewActivity::class),
1717
BytecodeSample("OkHttp", BytecodeOkHttpActivity::class),
18+
BytecodeSample("FCM Push Notifications", BytecodeFcmPushNotificationActivity::class),
1819
)
1920

2021
@Composable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.embrace.android.exampleapp.ui.examples.bytecode
2+
3+
import android.annotation.SuppressLint
4+
import android.util.Log
5+
import com.google.firebase.messaging.FirebaseMessagingService
6+
import com.google.firebase.messaging.RemoteMessage
7+
8+
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
9+
class ExamplePushNotificationService : FirebaseMessagingService() {
10+
11+
override fun onMessageReceived(message: RemoteMessage) {
12+
super.onMessageReceived(message)
13+
Log.d("EmbraceExample", "Message received: ${message.data}")
14+
}
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/target_activity_layout"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:padding="16dp">
8+
9+
<TextView
10+
android:id="@+id/target_text"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_gravity="center_horizontal"
14+
android:gravity="center_horizontal"
15+
android:text="Click the button to simulate a FCM push notification."
16+
android:textSize="18sp"
17+
android:textStyle="bold" />
18+
19+
<Button
20+
android:id="@+id/btn_bytecode_fcm_push_notification"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:layout_gravity="center_horizontal"
24+
android:padding="8dp"
25+
android:text="Click me" />
26+
27+
</LinearLayout>

examples/ExampleApp/gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ embrace = "7.3.0"
1212
navigationCompose = "2.8.9"
1313
okhttp = "4.12.0"
1414
otel = "1.49.0"
15+
firebase = "24.1.1"
1516

1617
[libraries]
1718
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -33,13 +34,15 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
3334
opentelemetry-bom = { group = "io.opentelemetry", name = "opentelemetry-bom", version.ref = "otel" }
3435
opentelemetry-api = { group = "io.opentelemetry", name = "opentelemetry-api"}
3536
opentelemetry-sdk = { group = "io.opentelemetry", name = "opentelemetry-sdk"}
37+
firebase-messaging = { group = "com.google.firebase", name = "firebase-messaging", version.ref = "firebase" }
3638

3739
embrace-android-api = { group = "io.embrace", name = "embrace-android-api", version.ref = "embrace" }
3840
embrace-android-sdk = { group = "io.embrace", name = "embrace-android-sdk", version.ref = "embrace" }
3941
embrace-android-core = { group = "io.embrace", name = "embrace-android-core", version.ref = "embrace" }
4042
embrace-android-features = { group = "io.embrace", name = "embrace-android-features", version.ref = "embrace" }
4143
embrace-android-payload = { group = "io.embrace", name = "embrace-android-payload", version.ref = "embrace" }
4244
embrace-android-delivery = { group = "io.embrace", name = "embrace-android-delivery", version.ref = "embrace" }
45+
embrace-android-fcm = { module = "io.embrace:embrace-android-fcm", version.ref = "embrace" }
4346

4447
[plugins]
4548
android-application = { id = "com.android.application", version.ref = "agp" }

0 commit comments

Comments
 (0)