re-register when network state changes to CONNECTED
This commit is contained in:
@ -4,9 +4,10 @@ import android.Manifest
|
||||
import android.app.Notification.VISIBILITY_PUBLIC
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.PendingIntent.getActivity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
@ -23,7 +24,7 @@ import android.view.*
|
||||
import android.util.Log
|
||||
import android.widget.RelativeLayout
|
||||
import android.media.AudioManager
|
||||
import android.os.SystemClock
|
||||
import android.net.NetworkInfo
|
||||
import android.support.v7.app.NotificationCompat
|
||||
import android.support.v7.view.menu.ActionMenuItemView
|
||||
import android.text.Editable
|
||||
@ -79,6 +80,19 @@ class MainActivity : AppCompatActivity() {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setContent(RemoteViews(getPackageName(), R.layout.notification))
|
||||
|
||||
val intentFilter = IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")
|
||||
val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val intentExtras = intent.extras
|
||||
val info = intentExtras.getParcelable<NetworkInfo>("networkInfo")
|
||||
if (running && (info.state == NetworkInfo.State.CONNECTED)) {
|
||||
Log.d("Baresip", "Registering upon CONNECTED event")
|
||||
UserAgent.register(uas)
|
||||
}
|
||||
}
|
||||
}
|
||||
registerReceiver(receiver, intentFilter)
|
||||
|
||||
aorSpinner = findViewById(R.id.AoRList) as Spinner
|
||||
uaAdapter = UaSpinnerAdapter(applicationContext, uas, images)
|
||||
aorSpinner.adapter = uaAdapter
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.util.Log
|
||||
|
||||
class UserAgent (val uap: String) {
|
||||
|
||||
val account = Account(ua_account(uap))
|
||||
@ -13,20 +15,19 @@ class UserAgent (val uap: String) {
|
||||
external fun ua_isregistered(ua: String): Boolean
|
||||
external fun ua_unregister(ua: String)
|
||||
|
||||
fun userAgents(): ArrayList<UserAgent> {
|
||||
val res = ArrayList<UserAgent>()
|
||||
for (ua in MainActivity.uas) {
|
||||
res.add(ua)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun find(uas: ArrayList<UserAgent>, uap: String): UserAgent? {
|
||||
for (u in uas) {
|
||||
if (u.uap == uap) return u
|
||||
for (ua in uas) {
|
||||
if (ua.uap == uap) return ua
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun register(uas: ArrayList<UserAgent>) {
|
||||
for (ua in uas) {
|
||||
if (ua_register(ua.uap) != 0)
|
||||
Log.e("Baresip", "Failed to register ${ua.aor}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user