Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to Develop : Firebase Crashlytics + Messaging #21

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ buildscript {
}
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:2.44"
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
}
}
plugins {
Expand Down
8 changes: 8 additions & 0 deletions presentaion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
id 'kotlinx-serialization'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}

android {
Expand Down Expand Up @@ -73,6 +75,12 @@ dependencies {
// lottie
implementation 'com.airbnb.android:lottie-compose:5.2.0'

// firebase service
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'

// default
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion presentaion/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".di.SchoolMateApp"
android:allowBackup="true"
Expand All @@ -27,7 +30,28 @@
android:name=".ui.main.MainActivity"
android:exported="false"
android:theme="@style/Theme.SchoolMate"
android:windowSoftInputMode="adjustResize"/>
android:windowSoftInputMode="adjustResize" />

<service
android:name=".service.MessagingService"
android:directBootAware="true"
android:exported="false"
android:icon="@drawable/ic_notification"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/primary" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Created by PangMoo on 2022/12/9
*/

package com.haeyum.schoolmate.service

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.media.RingtoneManager
import android.provider.Settings
import androidx.core.app.NotificationCompat
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.haeyum.schoolmate.R
import com.haeyum.schoolmate.ui.intro.IntroActivity

class MessagingService : FirebaseMessagingService() {
private val channelId by lazy {
getString(R.string.notification_channel_id)
}

override fun onNewToken(token: String) {
super.onNewToken(token)
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
val title = remoteMessage.notification?.title
val body = remoteMessage.notification?.body
val data = remoteMessage.data

val intent = Intent(applicationContext, IntroActivity::class.java).apply {
data.forEach { (key, value) ->
putExtra(key, value)
}
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}

val pendingIntent = PendingIntent.getActivity(
this, System.currentTimeMillis().toInt(), intent,
PendingIntent.FLAG_IMMUTABLE
)

val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_notification))
.setContentTitle(title)
.setContentText(body)
.setSound(defaultSoundUri)
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
.setAutoCancel(true)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setContentIntent(pendingIntent)

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

val channel = NotificationChannel(
channelId,
"스쿨메이트 알림",
NotificationManager.IMPORTANCE_DEFAULT
)
notificationManager.createNotificationChannel(channel)

notificationManager.notify(System.currentTimeMillis().toInt(), notificationBuilder.build())
}
}
1 change: 1 addition & 0 deletions presentaion/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="primary">#FF4564FF</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
1 change: 1 addition & 0 deletions presentaion/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">스쿨메이트</string>
<string name="title_activity_intro">IntroActivity</string>
<string name="notification_channel_id">notification_school_mate</string>
</resources>