|
|
|
|
@ -4,6 +4,7 @@ import android.Manifest |
|
|
|
|
import android.app.Activity |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.content.pm.PackageManager |
|
|
|
|
import android.os.Build |
|
|
|
|
import android.provider.MediaStore |
|
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
@ -136,6 +137,7 @@ open class MediaActivity : BaseActivity() { |
|
|
|
|
selectedChoice = -1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Build.VERSION.SDK_INT < Build.VERSION_CODES.R && |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Open the Camera Intent |
|
|
|
|
@ -147,16 +149,11 @@ open class MediaActivity : BaseActivity() { |
|
|
|
|
this.mCurrentPhotoPath = null |
|
|
|
|
this.multiplePictures = multiplePictures |
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
|
} |
|
|
|
|
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 200) { granted -> |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || granted) { |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
try { |
|
|
|
|
tempFile = ImageUtils.createImageFile(this) |
|
|
|
|
@ -175,9 +172,19 @@ open class MediaActivity : BaseActivity() { |
|
|
|
|
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 |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Open the gallery intent |
|
|
|
|
@ -188,20 +195,32 @@ open class MediaActivity : BaseActivity() { |
|
|
|
|
|
|
|
|
|
this.multiplePictures = multiplePictures |
|
|
|
|
|
|
|
|
|
// Test if we have the permission |
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
selectedChoice = SELECTED_CHOICE_SELECT_PICTURE |
|
|
|
|
askForStoragePermission() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.multiplePictures = multiplePictures |
|
|
|
|
|
|
|
|
|
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 201) { granted -> |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || granted) { |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test if we have the permission |
|
|
|
|
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
// selectedChoice = SELECTED_CHOICE_SELECT_PICTURE |
|
|
|
|
// askForStoragePermission() |
|
|
|
|
// 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 |
|
|
|
|
|