如何显示Agora一对一视频通话应用程序的来电通知

时间:2019-10-15 04:34:27

标签: android agora.io

自从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
        )
    }

1 个答案:

答案 0 :(得分:0)

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

Android:https://github.com/AgoraIO/Advanced-Video/tree/master/Calling-Interface/Agora-RTC-With-ConnectionService-Android

IOS:https://github.com/AgoraIO/Advanced-Video/tree/master/Calling-Interface/Agora-RTC-With-CallKit