check that network connection exists at application start
This commit is contained in:
@ -881,4 +881,4 @@ Java_com_tutpro_baresip_Utils_uri_1decode(JNIEnv *env, jobject thiz, jstring jav
|
||||
int res = uri_decode(&uri2, &pl);
|
||||
(*env)->ReleaseStringUTFChars(env, javaUri, uri);
|
||||
return res == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,9 +37,11 @@ class AccountsActivity : AppCompatActivity() {
|
||||
} else if (Account.exists(MainActivity.uas, aor)) {
|
||||
Log.e("Baresip", "Account $aor already exists")
|
||||
} else {
|
||||
if (UserAgent.ua_alloc("<$aor>;regq=0.5;pubint=0;regint=600") != 0)
|
||||
if (UserAgent.ua_alloc("<$aor>;regq=0.5;pubint=0;regint=600") != 0) {
|
||||
Log.e("Baresip", "Failed to allocate UA $aor")
|
||||
else {
|
||||
Utils.alertView(this, "Notice",
|
||||
"Failed to allocate new account. Check your network connection.")
|
||||
} else {
|
||||
SystemClock.sleep(200);
|
||||
newAorView.setText("")
|
||||
newAorView.setHint("SIP URI user@domain")
|
||||
|
||||
@ -4,6 +4,7 @@ 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.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
@ -22,6 +23,7 @@ import android.view.*
|
||||
import android.util.Log
|
||||
import android.widget.RelativeLayout
|
||||
import android.media.AudioManager
|
||||
import android.os.SystemClock
|
||||
import android.support.v7.app.NotificationCompat
|
||||
import android.support.v7.view.menu.ActionMenuItemView
|
||||
import android.text.Editable
|
||||
@ -312,9 +314,16 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
if (!running) {
|
||||
Log.i("Baresip", "Starting Baresip with path $path")
|
||||
nm.notify(NOTIFICATION_ID, nb.build())
|
||||
Thread(Runnable { baresipStart(path) }).start()
|
||||
running = true
|
||||
if (!Utils.isConnected(this)) {
|
||||
Toast.makeText(this, "No network connection!",
|
||||
Toast.LENGTH_LONG).show()
|
||||
finish()
|
||||
// System.exit(0)
|
||||
} else {
|
||||
nm.notify(NOTIFICATION_ID, nb.build())
|
||||
Thread(Runnable { baresipStart(path) }).start()
|
||||
running = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@ package com.tutpro.baresip
|
||||
import android.content.Context
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkInfo
|
||||
|
||||
import java.io.*
|
||||
|
||||
@ -115,6 +117,17 @@ object Utils {
|
||||
return res
|
||||
}
|
||||
|
||||
fun isConnected(context: Context): Boolean {
|
||||
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val activeNetwork = cm.activeNetworkInfo
|
||||
if (activeNetwork != null && activeNetwork.isConnected) {
|
||||
val networkType = activeNetwork.type
|
||||
return networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_MOBILE
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
external fun cmd_exec(cmd: String): Int
|
||||
external fun uri_decode(uri: String): Boolean
|
||||
external fun audio_codecs(): String
|
||||
|
||||
Reference in New Issue
Block a user