-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show notification for new friend request
- Loading branch information
1 parent
3a750e8
commit 590c064
Showing
70 changed files
with
16,785 additions
and
5 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
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
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/android/beastchat/Notification/FriendRequestMessagingService.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,74 @@ | ||
package com.android.beastchat.Notification | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.media.RingtoneManager | ||
import android.os.Build | ||
import androidx.core.app.NotificationCompat | ||
import com.android.beastchat.Activities.FriendsActivity | ||
import com.android.beastchat.R | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
|
||
class FriendRequestMessagingService : FirebaseMessagingService() { | ||
override fun onMessageReceived(p0: RemoteMessage) { | ||
super.onMessageReceived(p0) | ||
var title = p0.data!!["title"] | ||
var body = p0.data!!["body"] | ||
sendNotification(title!!, body!!) | ||
|
||
} | ||
|
||
@SuppressLint("WrongConstant") | ||
private fun sendNotification(title: String, body: String) { | ||
val intent = Intent(this, FriendsActivity::class.java) | ||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP | ||
val pendingIntent = PendingIntent.getActivity( | ||
this, | ||
0, | ||
intent, | ||
PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
val pattern: Array<Long> = arrayOf( | ||
500,500,500,500,500 | ||
) | ||
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | ||
|
||
val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
|
||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
// nm.createNotificationChannel( | ||
// NotificationChannel("first","FriendRequest", | ||
// NotificationManager.IMPORTANCE_HIGH) | ||
// ) | ||
val importance = NotificationManager.IMPORTANCE_HIGH | ||
var mChannel = nm.getNotificationChannel("first") | ||
if(mChannel == null) { | ||
mChannel = NotificationChannel("first", "FriendRequest", importance) | ||
mChannel!!.description = "FriendRequest" | ||
mChannel!!.enableVibration(true) | ||
mChannel!!.lightColor = Color.BLUE | ||
mChannel!!.vibrationPattern = pattern!!.toLongArray() | ||
nm.createNotificationChannel(mChannel) | ||
} | ||
} | ||
|
||
val clickableNotification = NotificationCompat.Builder(this, "first") | ||
.setContentTitle(title) | ||
.setContentText(body) | ||
.setVibrate(pattern.toLongArray()) | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) | ||
.setLights(Color.BLUE, 1, 1) | ||
.setSound(defaultSoundUri) | ||
.setContentIntent(pendingIntent) | ||
.setPriority(NotificationCompat.PRIORITY_HIGH) | ||
|
||
nm.notify(0, clickableNotification.build()) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.