Skip to content

Commit

Permalink
Fixes #26 by only asking user for camera permissions only
Browse files Browse the repository at this point in the history
  • Loading branch information
IzHoBX committed Jun 28, 2020
1 parent 8e04fcf commit 40a187c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/src/main/java/com/izho/saveentry/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ class MainActivity : AppCompatActivity() {

override fun onResume() {
super.onResume()
if (!Utils.allPermissionsGranted(this)) {
Utils.requestRuntimePermissions(this)
}

Utils.requestCameraPermissionIfNotGranted(this)
setSelectedTab()
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/izho/saveentry/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.requestPermissions
import androidx.core.content.ContextCompat
import androidx.exifinterface.media.ExifInterface
import com.izho.saveentry.CAMERA_PERMISSSION_REQUEST_CODE
import com.izho.saveentry.camera.CameraSizePair
import java.io.IOException
import java.io.InputStream
Expand Down Expand Up @@ -71,6 +74,12 @@ object Utils {
}
}

fun requestCameraPermissionIfNotGranted(activity: Activity) {
if(ContextCompat.checkSelfPermission(activity, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(Array<String>(1, {index -> android.Manifest.permission.CAMERA}), CAMERA_PERMISSSION_REQUEST_CODE)
}
}

internal fun allPermissionsGranted(context: Context): Boolean = getRequiredPermissions(context)
.all { checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED }

Expand Down

0 comments on commit 40a187c

Please sign in to comment.