Не получать события с помощью BroadcastReceiverAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Не получать события с помощью BroadcastReceiver

Сообщение Anonymous »

В моем проекте Android есть два класса:

Код: Выделить всё

class NotificationEventListener: NotificationListenerService() {

override fun onNotificationPosted(sbn: StatusBarNotification?) {
super.onNotificationPosted(sbn)

Log.i("NotificationEventListener", "Sending broadcast")
sendBroadcast(
Intent("com.github.example.TEST")
)
}

override fun onNotificationRemoved(sbn: StatusBarNotification?) {
super.onNotificationRemoved(sbn)
}
}
И:

Код: Выделить всё

class WatchCompanionDeviceService : CompanionDeviceService() {
@SuppressLint("MissingPermission")
override fun onDeviceAppeared(associationInfo: AssociationInfo) {
super.onDeviceAppeared(associationInfo)
// Unrelated bluetooth code
}

override fun onDeviceDisappeared(associationInfo: AssociationInfo) {
super.onDeviceDisappeared(associationInfo)
// Unrelated bluetooth code
}

private val notificationReceiver = NotificationReceiver()

override fun onCreate() {
super.onCreate()
Log.i("WatchCompanionDeviceService", "CompanionDeviceService started")

// Notification Receiver
val notificationFilter = IntentFilter("com.github.example.TEST")
registerReceiver(notificationReceiver, notificationFilter, RECEIVER_NOT_EXPORTED)
Log.i("WatchCompanionDeviceService", "notificationFilter started")
}

override fun onDestroy() {
super.onDestroy()
Log.i("WatchCompanionDeviceService", "CompanionDeviceService stopped")

// Notification Receiver
unregisterReceiver(notificationReceiver)
}

class NotificationReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.i("WatchCompanionDeviceService", "Broadcast received")
}
}
}

Когда я запускаю приложение и подключаю устройство Bluetooth, у меня запускается CompanionDeviceService и NotificationFilter Start.

Когда мой телефон получает уведомление. Я получаю сообщение журнала отправки широковещательной рассылки.

Итак, каждая ее часть работает, за исключением того, что широковещательная рассылка не принимается WatchCompanionDeviceService, я никогда получить полученную трансляцию сообщение журнала.


Подробнее здесь: https://stackoverflow.com/questions/793 ... streceiver
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»