1

由于 Agora 通过创建一个频道来工作,如何向其他用户显示有呼叫。我认为的一种方法是创建一个服务,该服务将使用改造来监听服务器,如果调用状态发生变化,我会将其显示给他,但在 android 后台服务受到限制。我认为的另一种方法是使用调度程序创建广播接收器。任何人都可以在这方面提供帮助。

class CallReciever : BroadcastReceiver() {
    val REQUEST_CODE : Int= 12345
    val ACTION :String= "com.codepath.example.servicesdemo.alarm"
    override fun onReceive(context: Context, intent: Intent) {
        val i = Intent(context, MyTestService::class.java)
        startWakefulService(context, i)
    }
}
class MyTestService : IntentService("MyTestService") {

    override fun onHandleIntent(intent: Intent?) {
        // Do the task here
       getBanner()
    }
    private fun getBanner() {

        val service = RetrofitCall.provideRetrofit().create(callrecieveAPI::class.java)
        val call = service.banner()

        call.enqueue(object : Callback<CallReceivePOJO> {
            override fun onResponse(call: Call<CallReceivePOJO>, response: Response<CallReceivePOJO>) {
                //showFailureDialog(GuestCheckoutActivity.this, response.body().getMessage());

                CommonObjects.channelid =response.body()!!.data.toString()

            }

            override fun onFailure(call: Call<CallReceivePOJO>, t: Throwable) {
                // handle execution failures like no internet connectivity

            }
        })

    }
}
class SplashActivity : AppCompatActivity() {

     override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        scheduleAlarm()
        object : CountDownTimer(5000, 1000) {
            override fun onFinish() { 
                     intent = Intent(applicationContext, VideoChatViewActivity::class.java)
                    startActivity(intent)

            }

            override fun onTick(p0: Long) {}
        }.start()
    }


    fun scheduleAlarm() {
        // Construct an intent that will execute the AlarmReceiver
        val intent = Intent(applicationContext, CallReciever::class.java)
        // Create a PendingIntent to be triggered when the alarm goes off
        val pIntent = PendingIntent.getBroadcast(
            this, REQUEST_CODE,
            intent, PendingIntent.FLAG_UPDATE_CURRENT
        )
        // Setup periodic alarm every every half hour from this point onwards
        val firstMillis = System.currentTimeMillis() // alarm is set right away
        val alarm = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        // First parameter is the type: ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC_WAKEUP
        // Interval can be INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_DAY
        alarm.setInexactRepeating(
            AlarmManager.RTC_WAKEUP, firstMillis,
            10000, pIntent
        )
    }
4

1 回答 1

0

Agora 有一些示例应用程序展示了如何使用 Agora 的视频和实时消息 SDK 以及原生 API (Android 的 ConnectionService 和 iOS 的 CallKit)来实现“呼叫”功能。

安卓:https ://github.com/AgoraIO-Usecase/Video-Calling/tree/master/OpenDuo-Android

IOS:https ://github.com/AgoraIO-Usecase/Video-Calling/tree/master/OpenDuo-iOS

于 2019-12-12T15:15:20.953 回答