Останов приемника вещания - PullRequest
0 голосов
/ 02 октября 2019

В моем приложении у меня широковещательный приемник.


Я получил сообщение от firebase , это сообщение отправляет намерение получателю.

Ресивер обновляет состояние приложения и после проверки наличия условия запускает плеер.

Когда мое приложение какое-то время было открыто, приемник отключался.
Когда приходит сообщение, оно ничего не делает.

Почему эта проблема?
Спасибо и извините за мой английский.

Получатель:

class CustomNotificationReceiver(val presenter: OrderListContract.Presenter,
                             val ordstatsfilt: String?) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
    if(intent.action == "com.woocommerce.app.NOTIFICATION") {
        presenter.loadOrders(ordstatsfilt, forceRefresh = true)
        if (inlavorazione > 0) {
            try {                 
                var uri: Uri? = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/" + R.raw.cha_ching)
                        ?: null
                Log.d("debugsto prendendo il file", "valore uri = $uri")
                //verifico l'uri
                Log.d("debugsto prendendo il file", "debudcprima" + uri)
                if (uri != null) {
                    Log.d("debugsto prendendo il file", "Sono dentro if uri")
                    if (!player.isPlaying && urice==0) {
                        Log.d("firebase", "sono nell'if")
                        player.setDataSource(context, uri)
                        Log.d("firebase", "sono nell'if2")
                        player.prepare();
                        urice=1
                    }
                    if (inlavorazione > 0) {
                          if (!player.isPlaying) {
                            Log.d("debugparte il file", "debugparteil file")
                            try {
                                Handler().postDelayed({
                                    player.start()
                                }, 5000)
                            } catch (e: Exception) {
                                e.printStackTrace()
                            }

                        }
                    }/*else{
                    if(player.isPlaying) player.stop()
                }*/


                    player.setOnCompletionListener {
                        if (inlavorazione > 0) {
                            if (!player.isPlaying) {

                                try {
                                    Handler().postDelayed({
                                        player.start()
                                    }, 3000)
                                } catch (e: Exception) {
                                    e.printStackTrace()
                                }
                            }
                        }/*else{
                        if(player.isPlaying) {player.stop()
                            inlavorazione=0}
                    }*/
                    }
                }
            } catch (e: Exception) {
                e.printStackTrace();
            }
        }
    }
}

Намерение:

 Intent().also { intent ->
        intent.setAction("com.woocommerce.app.NOTIFICATION")        //tag per l'azione
        //intent.putExtra("data", "Notice me senpai!")
        sendBroadcast(intent) //invio l'intent tramite broadcast
    }

...

приходит сообщение, inlavorazione ++, отправляет намерение, загружает приемник из базы данных и воспроизводит звук. Через некоторое время приемник явно не останавливается. Он не обновляет и не воспроизводит звук.

...