android notification policy/content
This commit is contained in:
parent
fa6e399aab
commit
d1d3f23f82
|
@ -68,52 +68,69 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
val handle = if (evt.EventType == "NewMessageFromPeer") data.getString("RemotePeer") else data.getString("GroupID");
|
val handle = if (evt.EventType == "NewMessageFromPeer") data.getString("RemotePeer") else data.getString("GroupID");
|
||||||
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
||||||
|
|
||||||
val loader = FlutterInjector.instance().flutterLoader()
|
|
||||||
val key = loader.getLookupKeyForAsset("assets/" + data.getString("picture"))//"assets/profiles/001-centaur.png")
|
|
||||||
val fh = applicationContext.assets.open(key)
|
|
||||||
|
|
||||||
val notification = data["notification"]
|
val notification = data["notification"]
|
||||||
|
|
||||||
if (notification != "None") {
|
|
||||||
|
|
||||||
|
|
||||||
if (notification == "SimpleEvent") {
|
if (notification == "SimpleEvent") {
|
||||||
|
val channelId =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createMessageNotificationChannel("Cwtch", "Cwtch")
|
||||||
|
} else {
|
||||||
|
// If earlier version channel ID is not used
|
||||||
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
||||||
|
intent.action = Intent.ACTION_RUN
|
||||||
|
intent.putExtra("EventType", "NotificationClicked")
|
||||||
|
}
|
||||||
|
|
||||||
|
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
||||||
|
.setContentTitle("Cwtch")
|
||||||
|
.setContentText("New message")//todo: translate
|
||||||
|
.setSmallIcon(R.mipmap.knott_transparent)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
notificationManager.notify(getNotificationID("Cwtch", "Cwtch"), newNotification)
|
||||||
} else if (notification == "ContactInfo") {
|
} else if (notification == "ContactInfo") {
|
||||||
|
val channelId =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createMessageNotificationChannel(handle, handle)
|
||||||
|
} else {
|
||||||
|
// If earlier version channel ID is not used
|
||||||
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
val loader = FlutterInjector.instance().flutterLoader()
|
||||||
|
val key = loader.getLookupKeyForAsset("assets/" + data.getString("Picture"))//"assets/profiles/001-centaur.png")
|
||||||
|
val fh = applicationContext.assets.open(key)
|
||||||
|
|
||||||
|
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
||||||
|
intent.action = Intent.ACTION_RUN
|
||||||
|
intent.putExtra("EventType", "NotificationClicked")
|
||||||
|
intent.putExtra("ProfileOnion", data.getString("ProfileOnion"))
|
||||||
|
intent.putExtra("Handle", handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
||||||
|
.setContentTitle(data.getString("Nick"))
|
||||||
|
.setContentText("New message")//todo: translate
|
||||||
|
.setLargeIcon(BitmapFactory.decodeStream(fh))
|
||||||
|
.setSmallIcon(R.mipmap.knott_transparent)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val channelId =
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
createMessageNotificationChannel(handle, handle)
|
|
||||||
} else {
|
|
||||||
// If earlier version channel ID is not used
|
|
||||||
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
val loader = FlutterInjector.instance().flutterLoader()
|
|
||||||
val key = loader.getLookupKeyForAsset("assets/" + data.getString("Picture"))//"assets/profiles/001-centaur.png")
|
|
||||||
val fh = applicationContext.assets.open(key)
|
|
||||||
|
|
||||||
|
|
||||||
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
|
||||||
intent.action = Intent.ACTION_RUN
|
|
||||||
intent.putExtra("EventType", "NotificationClicked")
|
|
||||||
intent.putExtra("ProfileOnion", data.getString("ProfileOnion"))
|
|
||||||
intent.putExtra("Handle", handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
|
||||||
.setContentTitle(data.getString("Nick"))
|
|
||||||
.setContentText("New message")//todo: translate
|
|
||||||
.setLargeIcon(BitmapFactory.decodeStream(fh))
|
|
||||||
.setSmallIcon(R.mipmap.knott_transparent)
|
|
||||||
.setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
|
||||||
.setAutoCancel(true)
|
|
||||||
.build()
|
|
||||||
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (evt.EventType == "FileDownloadProgressUpdate") {
|
} else if (evt.EventType == "FileDownloadProgressUpdate") {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue