Permissions fix

This commit is contained in:
Hardcore Sushi 2020-08-12 16:14:26 +02:00
parent be17e5687d
commit afda604805
3 changed files with 59 additions and 31 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="sushi.hardcore.droidfs"> package="sushi.hardcore.droidfs">
<permission <permission
@ -10,7 +11,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" /> <uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" /> <uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove"/>
<application <application
android:name=".ColoredApplication" android:name=".ColoredApplication"

View File

@ -1,13 +1,14 @@
package sushi.hardcore.droidfs package sushi.hardcore.droidfs
import android.content.Intent import android.Manifest
import android.graphics.Color import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.EditText import android.widget.EditText
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat
import com.otaliastudios.cameraview.CameraListener import com.otaliastudios.cameraview.CameraListener
import com.otaliastudios.cameraview.PictureResult import com.otaliastudios.cameraview.PictureResult
import com.otaliastudios.cameraview.controls.Facing import com.otaliastudios.cameraview.controls.Facing
@ -216,10 +217,19 @@ class CameraActivity : BaseActivity() {
} }
} }
override fun onStop() {
super.onStop()
if (!isFinishing){
finish()
}
}
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){ //if not asking for permission
finish() finish()
} }
}
override fun onBackPressed() { override fun onBackPressed() {
super.onBackPressed() super.onBackPressed()

View File

@ -27,18 +27,35 @@ class MainActivity : BaseActivity() {
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSIONS_REQUEST) requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSIONS_REQUEST)
} else {
if (checkStorageAvailability()){
checkFirstOpening()
} }
} }
}
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
image_logo.layoutParams.height = (metrics.heightPixels/2.2).toInt()
Glide.with(this).load(R.drawable.logo).into(image_logo)
}
private fun checkStorageAvailability(): Boolean {
val state = Environment.getExternalStorageState() val state = Environment.getExternalStorageState()
val storageAvailable = Environment.MEDIA_MOUNTED == state || Environment.MEDIA_MOUNTED_READ_ONLY == state val storageAvailable = Environment.MEDIA_MOUNTED == state || Environment.MEDIA_MOUNTED_READ_ONLY == state
if (!storageAvailable) { return if (!storageAvailable) {
ColoredAlertDialogBuilder(this) ColoredAlertDialogBuilder(this)
.setTitle(R.string.storage_unavailable) .setTitle(R.string.storage_unavailable)
.setMessage(R.string.storage_unavailable_msg) .setMessage(R.string.storage_unavailable_msg)
.setPositiveButton(R.string.ok .setCancelable(false)
) { _, _ -> finish() }.show() .setPositiveButton(R.string.ok) { _, _ -> finish() }.show()
false
} else {
true
} }
if (!sharedPrefs.getBoolean("alreadyLaunched", false)){ }
private fun checkFirstOpening() {
if (sharedPrefs.getBoolean("applicationFirstOpening", true)){
ColoredAlertDialogBuilder(this) ColoredAlertDialogBuilder(this)
.setTitle(R.string.warning) .setTitle(R.string.warning)
.setMessage(R.string.usf_home_warning_msg) .setMessage(R.string.usf_home_warning_msg)
@ -49,13 +66,9 @@ class MainActivity : BaseActivity() {
startActivity(intent) startActivity(intent)
} }
.setNegativeButton(R.string.ok, null) .setNegativeButton(R.string.ok, null)
.setOnDismissListener { sharedPrefs.edit().putBoolean("alreadyLaunched", true).apply() } .setOnDismissListener { sharedPrefs.edit().putBoolean("applicationFirstOpening", false).apply() }
.show() .show()
} }
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
image_logo.layoutParams.height = (metrics.heightPixels/2.2).toInt()
Glide.with(this).load(R.drawable.logo).into(image_logo)
} }
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
@ -65,8 +78,11 @@ class MainActivity : BaseActivity() {
ColoredAlertDialogBuilder(this) ColoredAlertDialogBuilder(this)
.setTitle(R.string.storage_perm_denied) .setTitle(R.string.storage_perm_denied)
.setMessage(R.string.storage_perm_denied_msg) .setMessage(R.string.storage_perm_denied_msg)
.setPositiveButton(R.string.ok .setCancelable(false)
) { _, _ -> finish() }.show() .setPositiveButton(R.string.ok) { _, _ -> finish() }.show()
} else {
checkStorageAvailability()
checkFirstOpening()
} }
} }
} }