Fixes issue with android 30 for taking / selecting pictures

blinds
Laurent 4 years ago
parent fb4633c50d
commit 98d22219b0
  1. 6
      app/build.gradle
  2. 2
      app/src/main/AndroidManifest.xml
  3. 1
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  4. 3
      app/src/main/java/net/pokeranalytics/android/ui/activity/ImportActivity.kt
  5. 128
      app/src/main/java/net/pokeranalytics/android/ui/activity/components/MediaActivity.kt
  6. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt
  7. 4
      build.gradle
  8. 2
      gradle/wrapper/gradle-wrapper.properties

@ -15,8 +15,8 @@ repositories {
android { android {
compileSdkVersion 29 compileSdkVersion 30
buildToolsVersion "29.0.2" buildToolsVersion "30.0.2"
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
@ -34,7 +34,7 @@ android {
defaultConfig { defaultConfig {
applicationId "net.pokeranalytics.android" applicationId "net.pokeranalytics.android"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 29 targetSdkVersion 30
versionCode 125 versionCode 125
versionName "5.4.3" versionName "5.4.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

@ -9,6 +9,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<application <application
android:name=".PokerAnalyticsApplication" android:name=".PokerAnalyticsApplication"
android:allowBackup="true" android:allowBackup="true"

@ -63,6 +63,7 @@ class PokerAnalyticsApplication : Application() {
// Logs // Logs
Timber.plant(PokerAnalyticsLogs()) Timber.plant(PokerAnalyticsLogs())
} }
Timber.d("SDK version = ${Build.VERSION.SDK_INT}")
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Timber.d("UserPreferences.defaultCurrency: ${UserDefaults.currency.symbol}") Timber.d("UserPreferences.defaultCurrency: ${UserDefaults.currency.symbol}")

@ -9,6 +9,7 @@ import android.widget.Toast
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.activity.components.BaseActivity import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode import net.pokeranalytics.android.ui.activity.components.RequestCode
@ -49,7 +50,7 @@ class ImportActivity : BaseActivity() {
intent?.data?.let { intent?.data?.let {
this.fileURI = it this.fileURI = it
} ?: run { } ?: run {
this.fileURI = intent.getParcelableExtra(IntentKey.URI.keyName) as Uri this.fileURI = intent.getParcelableExtra(IntentKey.URI.keyName) ?: throw PAIllegalStateException("Uri not found")
} }
setContentView(R.layout.activity_import) setContentView(R.layout.activity_import)

@ -4,6 +4,7 @@ import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build
import android.provider.MediaStore import android.provider.MediaStore
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -136,6 +137,7 @@ open class MediaActivity : BaseActivity() {
selectedChoice = -1 selectedChoice = -1
} }
// Build.VERSION.SDK_INT < Build.VERSION_CODES.R &&
/** /**
* Open the Camera Intent * Open the Camera Intent
@ -147,35 +149,40 @@ open class MediaActivity : BaseActivity() {
this.mCurrentPhotoPath = null this.mCurrentPhotoPath = null
this.multiplePictures = multiplePictures this.multiplePictures = multiplePictures
// Test if we have the permission askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 200) { granted ->
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || granted) {
selectedChoice = SELECTED_CHOICE_TAKE_PICTURE
askForStoragePermission()
return
}
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(packageManager) != null) { // Create the File where the photo should go
// Create the File where the photo should go try {
try { tempFile = ImageUtils.createImageFile(this)
tempFile = ImageUtils.createImageFile(this) mCurrentPhotoPath = "file:" + tempFile?.absolutePath
mCurrentPhotoPath = "file:" + tempFile?.absolutePath } catch (ex: IOException) {
} catch (ex: IOException) { // Error occurred while creating the File
// Error occurred while creating the File }
}
// Continue only if the File was successfully created
if (tempFile != null) {
Timber.d("tempFile: ${tempFile?.absolutePath}")
val photoURI = FileProvider.getUriForFile(
this,
applicationContext.packageName + ".fileprovider", tempFile!!
)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE)
}
// Continue only if the File was successfully created
if (tempFile != null) {
Timber.d("tempFile: ${tempFile?.absolutePath}")
val photoURI = FileProvider.getUriForFile(
this,
applicationContext.packageName + ".fileprovider", tempFile!!
)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE)
} }
} }
// // Test if we have the permission
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// selectedChoice = SELECTED_CHOICE_TAKE_PICTURE
// askForStoragePermission()
// return
// }
} }
@ -188,20 +195,32 @@ open class MediaActivity : BaseActivity() {
this.multiplePictures = multiplePictures this.multiplePictures = multiplePictures
// Test if we have the permission askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 201) { granted ->
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || granted) {
selectedChoice = SELECTED_CHOICE_SELECT_PICTURE val galleryIntent = Intent()
askForStoragePermission() galleryIntent.type = "image/*"
return galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiplePictures)
galleryIntent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(galleryIntent, REQUEST_CODE_SELECT_PICTURE)
}
} }
this.multiplePictures = multiplePictures
val galleryIntent = Intent() // Test if we have the permission
galleryIntent.type = "image/*" // if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiplePictures) // selectedChoice = SELECTED_CHOICE_SELECT_PICTURE
galleryIntent.action = Intent.ACTION_GET_CONTENT // askForStoragePermission()
startActivityForResult(galleryIntent, REQUEST_CODE_SELECT_PICTURE) // return
// }
//
// this.multiplePictures = multiplePictures
//
// val galleryIntent = Intent()
// galleryIntent.type = "image/*"
// galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiplePictures)
// galleryIntent.action = Intent.ACTION_GET_CONTENT
// startActivityForResult(galleryIntent, REQUEST_CODE_SELECT_PICTURE)
} }
/** /**
@ -215,43 +234,6 @@ open class MediaActivity : BaseActivity() {
} }
} }
// /**
// * Ask for the acmera permission
// */
// private fun askForCameraPermission() {
// // Here, thisActivity is the current activity
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA),
// PERMISSION_REQUEST_CAMERA)
// }
// }
// /**
// * Ask for camera and storage permission
// */
// private fun askForCameraAndStoragePermissions() {
//
// val permissions = ArrayList<String>()
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// permissions.add(Manifest.permission.CAMERA)
// }
//
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
// }
//
// if (permissions.size > 0) {
// ActivityCompat.requestPermissions(this, permissions.toArray(arrayOfNulls<String>(permissions.size)), PERMISSION_REQUEST_CAMERA)
// }
// }
//
// /**
// * Called when a bitmap is return
// *
// * @param bitmap the bitmap returned
// */
// open fun getBitmapImage(file: File?, bitmap: Bitmap?) {}
/** /**
* Called when the user is adding new photos * Called when the user is adding new photos

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.modules.data
import android.app.Activity.RESULT_OK import android.app.Activity.RESULT_OK
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -189,7 +190,9 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
val builder = AlertDialog.Builder(requireContext()) val builder = AlertDialog.Builder(requireContext())
val placesArray = ArrayList<CharSequence>() val placesArray = ArrayList<CharSequence>()
placesArray.add(getString(R.string.take_a_picture)) if (requireActivity().packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
placesArray.add(getString(R.string.take_a_picture))
}
placesArray.add(getString(R.string.library)) placesArray.add(getString(R.string.library))
placesArray.add(getString(R.string.select_a_color)) placesArray.add(getString(R.string.select_a_color))

@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.10' ext.kotlin_version = '1.5.21'
repositories { repositories {
google() google()
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.3' classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.realm:realm-gradle-plugin:10.3.1' classpath 'io.realm:realm-gradle-plugin:10.3.1'

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

Loading…
Cancel
Save