kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Fix #37, show a Toast every time the app launches about missing permissions
rodzic
dbcc84b5e2
commit
a81edbf646
|
@ -211,9 +211,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
) != PackageManager.PERMISSION_GRANTED
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestPermission() {
|
private fun getMissingPermissions(): List<String> {
|
||||||
debug("Checking permissions")
|
|
||||||
|
|
||||||
val perms = mutableListOf(
|
val perms = mutableListOf(
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
@ -234,7 +232,13 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
perms.add(Manifest.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND)
|
perms.add(Manifest.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND)
|
||||||
}
|
}
|
||||||
|
|
||||||
val missingPerms = getMissingPermissions(perms)
|
return getMissingPermissions(perms)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun requestPermission() {
|
||||||
|
debug("Checking permissions")
|
||||||
|
|
||||||
|
val missingPerms = getMissingPermissions()
|
||||||
if (missingPerms.isNotEmpty()) {
|
if (missingPerms.isNotEmpty()) {
|
||||||
missingPerms.forEach {
|
missingPerms.forEach {
|
||||||
// Permission is not granted
|
// Permission is not granted
|
||||||
|
@ -263,6 +267,31 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remind user he's disabled permissions we need
|
||||||
|
*/
|
||||||
|
private fun warnMissingPermissions() {
|
||||||
|
// Older versions of android don't know about these permissions - ignore failure to grant
|
||||||
|
val ignoredPermissions = setOf(
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
|
Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND,
|
||||||
|
Manifest.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND
|
||||||
|
)
|
||||||
|
|
||||||
|
val deniedPermissions = getMissingPermissions().filter { name ->
|
||||||
|
!ignoredPermissions.contains(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deniedPermissions.isNotEmpty()) {
|
||||||
|
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
||||||
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
getString(R.string.permission_missing),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
override fun onRequestPermissionsResult(
|
||||||
requestCode: Int,
|
requestCode: Int,
|
||||||
permissions: Array<out String>,
|
permissions: Array<out String>,
|
||||||
|
@ -270,26 +299,6 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
) {
|
) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
|
||||||
// Older versions of android don't know about these permissions - ignore failure to grant
|
|
||||||
val ignoredPermissions = arrayOf(
|
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
||||||
Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND,
|
|
||||||
Manifest.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND
|
|
||||||
)
|
|
||||||
|
|
||||||
val deniedPermissions = permissions.filterIndexed { index, name ->
|
|
||||||
grantResults[index] == PackageManager.PERMISSION_DENIED &&
|
|
||||||
!ignoredPermissions.contains(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deniedPermissions.isNotEmpty()) {
|
|
||||||
warn("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
|
||||||
Toast.makeText(
|
|
||||||
this,
|
|
||||||
getString(R.string.permission_missing),
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
updateBluetoothEnabled()
|
updateBluetoothEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +429,6 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
handleIntent(intent)
|
handleIntent(intent)
|
||||||
|
@ -769,6 +777,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
|
warnMissingPermissions()
|
||||||
|
|
||||||
// Ask to start bluetooth if no USB devices are visible
|
// Ask to start bluetooth if no USB devices are visible
|
||||||
val hasUSB = SerialInterface.findDrivers(this).isNotEmpty()
|
val hasUSB = SerialInterface.findDrivers(this).isNotEmpty()
|
||||||
if (!isInTestLab && !hasUSB) {
|
if (!isInTestLab && !hasUSB) {
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<string name="map_not_allowed">You have analytics disabled. Unfortunately our map provider (mapbox) requires analytics to be allowed for their \'free\' plan. So we have turned off the map view.\n\n
|
<string name="map_not_allowed">You have analytics disabled. Unfortunately our map provider (mapbox) requires analytics to be allowed for their \'free\' plan. So we have turned off the map view.\n\n
|
||||||
If you would like to see the map, you\'ll need to turn on analytics in the Settings pane (also, for the time being you might need to force restart the application).\n\n
|
If you would like to see the map, you\'ll need to turn on analytics in the Settings pane (also, for the time being you might need to force restart the application).\n\n
|
||||||
If you are interested in us paying for mapbox (or switching to a different map provider), please post in meshtastic.discourse.group</string>
|
If you are interested in us paying for mapbox (or switching to a different map provider), please post in meshtastic.discourse.group</string>
|
||||||
<string name="permission_missing">A required permission is missing, Meshtastic won\'t be able to work properly. Please enable in application settings.</string>
|
<string name="permission_missing">A required permission is missing, Meshtastic won\'t be able to work properly. Please enable in Android application settings.</string>
|
||||||
<string name="radio_sleeping">Radio was sleeping, could not change channel</string>
|
<string name="radio_sleeping">Radio was sleeping, could not change channel</string>
|
||||||
<string name="report_bug">Report Bug</string>
|
<string name="report_bug">Report Bug</string>
|
||||||
<string name="report_a_bug">Report a bug</string>
|
<string name="report_a_bug">Report a bug</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue