-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5078338
commit ebc6b02
Showing
8 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "1073906460226", | ||
"firebase_url": "https://sulteng-covid-8d14c.firebaseio.com", | ||
"project_id": "sulteng-covid-8d14c", | ||
"storage_bucket": "sulteng-covid-8d14c.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:1073906460226:android:2bb8958993b4d4acc46fdb", | ||
"android_client_info": { | ||
"package_name": "id.husni.sultengcovid" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "1073906460226-a2k37h2l8v4q7aki0el2mgqar7n5aj47.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyCZlSFa_7NotKhedN7zwHagfzxfDOklkRw" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "1073906460226-a2k37h2l8v4q7aki0el2mgqar7n5aj47.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/src/main/java/id/husni/sultengcovid/serviceapi/FcmCloudMessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2020. | ||
* Made with ❤ by Moh Husni Mubaraq | ||
* Not For Commercial Purpose | ||
*/ | ||
|
||
package id.husni.sultengcovid.serviceapi | ||
|
||
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.net.Uri | ||
import android.os.Build | ||
import android.util.Log | ||
import androidx.core.app.NotificationCompat | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import id.husni.sultengcovid.R | ||
|
||
class FcmCloudMessageService : FirebaseMessagingService() { | ||
private var notifId = 1 | ||
companion object{ | ||
const val CHANNEL_ID = "channelOne" | ||
const val CHANNEL_NAME = "channelFcm" | ||
const val FCM_REQUEST_CODE = 100 | ||
const val limitNotif = 2 | ||
} | ||
|
||
override fun onNewToken(p0: String) { | ||
super.onNewToken(p0) | ||
Log.d("NEW TOKEN", p0) | ||
} | ||
|
||
override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
super.onMessageReceived(remoteMessage) | ||
remoteMessage.notification?.let { | ||
getNotification(it.body) | ||
notifId++ | ||
} | ||
} | ||
|
||
private fun getNotification(body: String?) { | ||
val intent = Intent() | ||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP | ||
val pendingIntent : PendingIntent = PendingIntent.getActivity(this,FCM_REQUEST_CODE, intent, PendingIntent.FLAG_ONE_SHOT) | ||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
val uriSound : Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | ||
val notificationBuilder : NotificationCompat.Builder | ||
|
||
if (notifId < limitNotif){ | ||
val largeIcon = BitmapFactory.decodeResource(resources,R.drawable.icon) | ||
notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID) | ||
.setContentText(body) | ||
.setSmallIcon(R.drawable.icon) | ||
.setAutoCancel(true) | ||
.setContentIntent(pendingIntent) | ||
.setVibrate(longArrayOf(1000,1000,1000,1000,1000)) | ||
.setSound(uriSound) | ||
.setLargeIcon(largeIcon) | ||
} | ||
else{ | ||
val inboxStyle = NotificationCompat.InboxStyle() | ||
.setBigContentTitle("s") | ||
.setSummaryText(notifId.toString() + getString(R.string.message)) | ||
.addLine(body) | ||
.addLine(body) | ||
|
||
notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID) | ||
.setContentText(body) | ||
.setSmallIcon(R.drawable.icon) | ||
.setAutoCancel(true) | ||
.setContentIntent(pendingIntent) | ||
.setVibrate(longArrayOf(1000,1000,1000,1000,1000)) | ||
.setSound(uriSound) | ||
.setStyle(inboxStyle) | ||
} | ||
|
||
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.O){ | ||
val channel = NotificationChannel(CHANNEL_ID,CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT) | ||
notificationManager.createNotificationChannel(channel) | ||
notificationBuilder.setChannelId(CHANNEL_ID) | ||
} | ||
val notification = notificationBuilder.build() | ||
notificationManager.notify(notifId,notification) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters