既然Agora是通过创建一个通道来工作的,那么如何才能向另一个用户显示有一个调用。我认为一种方法是创建一个服务,它将使用改造来监听服务器,如果调用状态发生变化,我将向他展示,但在安卓系统中,后台服务是受限的。另一种我认为是通过创建一个带有调度程序的广播接收器的方法。有人能帮上忙吗。
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
)
}发布于 2019-12-12 15:15:20
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
https://stackoverflow.com/questions/58387319
复制相似问题