Androidアプリ FireBase によるプッシュ通知実装

1.FireBase APP登録

2.FireBase -> google-service.json download -> AndroidStudio app 配下にコピー

3.
Project Level
project\build.gradle.kts

<!-- Add -->
buildscript {
dependencies {
classpath("com.google.gms:google-services:4.4.2")
}
}


App Level
project\app\build.gradle.kts

<!- Add -->
plugins {
id("com.android.application")
id("com.google.gms.google-services") -> Add
}

dependencies {
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.firebase:firebase-messaging:24.0.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}

4.FirebaseMessagingService Class の作成

public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}
}


5.AndroidManifest.xml に 上記 Service の登録

<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>


</application>

いいなと思ったら応援しよう!