Skip to content

Commit

Permalink
application will exit if permission are not grant
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdamiano committed Mar 26, 2018
1 parent bbf1dec commit e3cbfaf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mainActivity/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sierrawireless.avphone"
android:versionCode="48">
android:versionCode="49">

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ class MainActivity : FragmentActivity(), LoginListener, AuthenticationManager, O
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {

Log.w(TAG, "onRequestPermissionsResult: READ_PHONE_STATE answer ko")
longToast("Permission not granted please grant permission")

alert("Permission not granted. The application will exit now", "Alert") {
positiveButton("OK") {
finish()
}
}.show()
} else {
Log.d(TAG, " for READ PHONE STATE ok")
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Expand All @@ -264,7 +269,11 @@ class MainActivity : FragmentActivity(), LoginListener, AuthenticationManager, O
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {

Log.w(TAG, "onRequestPermissionsResult: ACCESS_COARSE_LOCATION answer ko")
longToast("Permission not granted please grant permission")
alert("Permission not granted. The application will exit now", "Alert") {
positiveButton("OK") {
finish()
}
}.show()
} else {
Log.d(TAG, " for COARSE LOCATION ok")
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ) {
Expand All @@ -279,7 +288,11 @@ class MainActivity : FragmentActivity(), LoginListener, AuthenticationManager, O
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {

Log.w(TAG, "onRequestPermissionsResult: answer ACCESS_FINE_LOCATION ko")
longToast("Permission not granted please grant permission")
alert("Permission not granted. The application will exit now", "Alert") {
positiveButton("OK") {
finish()
}
}.show()
}else{
Log.d(TAG, "for FINE LOCATION STATE ok")
}
Expand Down Expand Up @@ -330,7 +343,7 @@ class MainActivity : FragmentActivity(), LoginListener, AuthenticationManager, O
}

override fun onResume() {
Log.d(TAG, "OnResume Called")

super.onResume()
left_drawer.requestFocusFromTouch()
left_drawer.setItemChecked(lastPosition, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.text.TextUtils
import com.sierrawireless.avphone.activity.MainActivity
import org.jetbrains.anko.toast

object DeviceInfo {

Expand Down Expand Up @@ -67,23 +68,40 @@ object DeviceInfo {
fun getIMEI(context: Context): String? {

val telManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
return if (telManager.phoneType == TelephonyManager.PHONE_TYPE_GSM) {
@Suppress("DEPRECATION")
telManager.deviceId
} else null
var rc:String? = null
try {
rc = if (telManager.phoneType == TelephonyManager.PHONE_TYPE_GSM) {
@Suppress("DEPRECATION")
telManager.deviceId
} else null
}catch(e:SecurityException) {
MainActivity.instance.runOnUiThread {
MainActivity.instance.toast("Read Phone Permission not given")
}
}

return rc
}

fun getICCID(context: Context): String {
val sm = SubscriptionManager.from(context)
val sis = sm.activeSubscriptionInfoList
return if (sis != null) {
val si = sis[0]
si.iccId
}else{
""
var rc = ""
try {
rc = if (sis != null) {
val si = sis[0]
si.iccId
} else {
""
}
}catch(e:SecurityException) {
MainActivity.instance.runOnUiThread {
MainActivity.instance.toast("Read Phone Permission not given")
}
}

return rc


}
}

0 comments on commit e3cbfaf

Please sign in to comment.