Ниже этого класса Firebase, после получения уведомления я хочу показать нижний лист внутри составного объекта, одна модель представления связана с этим составным объектом,
class FireBaseNotificationServices(
private val NotificationRepository: NotificationRepository = Graph.notificationRepository
) : FirebaseMessagingService() {
private val firebaseViewModel: FirebaseViewModel by lazy {
FirebaseViewModel()
}
private val orderViewModel: OrderViewModel by lazy { OrderViewModel() }
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d(TAG, "From: ${remoteMessage.from}")
// Check if message contains a data payload.
if (remoteMessage.data.isNotEmpty()) {
Log.d(TAG, "Message data payload: ${remoteMessage.data}")
Log.d(TAG, "Message ID: ${remoteMessage.messageId}")
orderViewModel.setNotificationData(NotificationDataModel(id = 0, notification_type = "new order", notification_data = remoteMessage.data.toString()))
// Check if data needs to be processed by long running job
if (needsToBeScheduled()) {
// For long-running tasks (10 seconds or more) use WorkManager.
//scheduleJob(remoteMessage.data)
} else {
// Handle message within 10 seconds
handleNow()
}
}
// Check if message contains a notification payload.
remoteMessage.notification?.let {
Log.d(TAG, "Message Notification Body: ${it.title}")
Log.d(TAG, "Message Notification Body: ${it.body}")
sendNotification(remoteMessage.notification?.body.toString())
firebaseViewModel.setNotificationData(it.title.toString(), it.body.toString())
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
private fun needsToBeScheduled() = true
override fun onNewToken(token: String) {
sendRegistrationToServer(token)
}
private fun scheduleJob(remoteData: MutableMap) {
// [START dispatch_job]
val data = Data.Builder()
data.putString("orderId", remoteData["id"])
val work = OneTimeWorkRequest.Builder(MyWorker::class.java).setInputData(data.build())
.build()
WorkManager.getInstance(this)
.beginWith(work)
.enqueue()
// [END dispatch_job]
}
private fun handleNow() {
Log.d(TAG, "Short lived task is done.")
}
private fun sendRegistrationToServer(token: String?) {
Log.d(TAG, "sendRegistrationTokenToServer($token)")
setFirebaseToken(token.toString())
}
private fun sendNotification(messageBody: String) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val requestCode = 0
val pendingIntent = PendingIntent.getActivity(
this,
requestCode,
intent,
PendingIntent.FLAG_IMMUTABLE,
)
val channelId = "cws.pos.app"
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT,
)
notificationManager.createNotificationChannel(channel)
}
val notificationId = 0
notificationManager.notify(notificationId, notificationBuilder.build())
}
companion object {
private const val TAG = "MyFirebaseMsgService"
}
private var scope = MainScope()
private fun setFirebaseToken(id: String) {
val dataPref = DataPref(context = applicationContext)
scope.launch {
dataPref.setFirebaseToken(data = id)
}
}
internal class MyWorker(
appContext: Context, workerParams: WorkerParameters,
) :
Worker(appContext, workerParams) {
private val orderViewModel: OrderViewModel by lazy { OrderViewModel() }
override fun doWork(): Result {
val orderId = inputData.getString("orderId")
Log.d(TAG, "doWork: $orderId")
orderId?.let {
orderViewModel.setNotificationData(NotificationDataModel(id = 0, notification_type = "new order", notification_data = orderId))
}
return Result.success()
}
}
Ниже этого класса Firebase, после получения уведомления я хочу показать нижний лист внутри составного объекта, одна модель представления связана с этим составным объектом, class FireBaseNotificationServices( private val NotificationRepository: NotificationRepository = Graph.notificationRepository ) : FirebaseMessagingService() { [code]private val firebaseViewModel: FirebaseViewModel by lazy { FirebaseViewModel() }
private val orderViewModel: OrderViewModel by lazy { OrderViewModel() }
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d(TAG, "From: ${remoteMessage.from}")
// Check if message contains a data payload. if (remoteMessage.data.isNotEmpty()) { Log.d(TAG, "Message data payload: ${remoteMessage.data}") Log.d(TAG, "Message ID: ${remoteMessage.messageId}")
orderViewModel.setNotificationData(NotificationDataModel(id = 0, notification_type = "new order", notification_data = remoteMessage.data.toString()))
// Check if data needs to be processed by long running job if (needsToBeScheduled()) { // For long-running tasks (10 seconds or more) use WorkManager. //scheduleJob(remoteMessage.data) } else { // Handle message within 10 seconds handleNow() } }
// Check if message contains a notification payload. remoteMessage.notification?.let { Log.d(TAG, "Message Notification Body: ${it.title}") Log.d(TAG, "Message Notification Body: ${it.body}") sendNotification(remoteMessage.notification?.body.toString()) firebaseViewModel.setNotificationData(it.title.toString(), it.body.toString()) } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
private fun needsToBeScheduled() = true
override fun onNewToken(token: String) { sendRegistrationToServer(token) }
private fun scheduleJob(remoteData: MutableMap) { // [START dispatch_job] val data = Data.Builder() data.putString("orderId", remoteData["id"]) val work = OneTimeWorkRequest.Builder(MyWorker::class.java).setInputData(data.build()) .build()
Код, которым я поделился, в порядке, я могу получить данные уведомлений в logcat, но я хочу отображать данные уведомлений на одном из моих компонуемых экранов. Я не понял, как передать данные уведомления из класса firebaseNotificationService на мой...
Код, которым я поделился, в порядке, я могу получить данные уведомлений в logcat, но я хочу отображать данные уведомлений на одном из моих компонуемых экранов. Я не понял, как передать данные уведомлений из класса firebaseNotificationService на свой...
Я пытаюсь создать такое представление с возможностью прокрутки/перетаскивания, как на картах Google (последнее в этом районе). Это не нижний лист, я пытаюсь найти способ сделать это, но не могу найти правильный способ. я думаю, возможно, это сделано...
Я реализую пользовательский интерфейс, в котором над клавиатурой появится нижний лист с EditText, позволяющий пользователю ввести значение. Проблема в том, что вид частично перекрывается клавиатурой, закрывая нижнюю часть нижнего листа.