<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
+import androidx.preference.PreferenceManager
+import jp.osdn.gokigen.mangle.preference.PreferenceValueInitializer
import jp.osdn.gokigen.mangle.scene.MainButtonHandler
import jp.osdn.gokigen.mangle.scene.SceneChanger
import jp.osdn.gokigen.mangle.scene.ShowMessage
supportActionBar?.hide()
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ try
+ {
+ PreferenceValueInitializer().initializeStorageLocationPreferences(
+ PreferenceManager.getDefaultSharedPreferences(
+ this
+ )
+ )
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+
if (allPermissionsGranted())
{
checkMediaWritePermission()
}
}
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray)
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array<String>,
+ grantResults: IntArray
+ )
{
if (requestCode == REQUEST_CODE_PERMISSIONS)
{
{
Log.v(TAG, " WRITE PERMISSION GRANTED ${data}")
}
+ if ((requestCode == REQUEST_CODE_OPEN_DOCUMENT_TREE)&&(resultCode == RESULT_OK))
+ {
+ Log.v(TAG, " WRITE PERMISSION GRANTED ${data}")
+
+ data?.data?.also { uri ->
+ val contentResolver = applicationContext.contentResolver
+ val takeFlags: Int =
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
+ contentResolver.takePersistableUriPermission(uri, takeFlags)
+ PreferenceValueInitializer().storeStorageLocationPreference(
+ PreferenceManager.getDefaultSharedPreferences(
+ this
+ ), uri
+ )
+ }
+ }
}
companion object
{
private const val REQUEST_CODE_PERMISSIONS = 10
const val REQUEST_CODE_MEDIA_EDIT = 12
- private val REQUIRED_PERMISSIONS = arrayOf(Manifest.permission.CAMERA,
- Manifest.permission.VIBRATE,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ const val REQUEST_CODE_OPEN_DOCUMENT_TREE = 20
+
+ private val REQUIRED_PERMISSIONS = arrayOf(
+ Manifest.permission.CAMERA,
+ Manifest.permission.VIBRATE,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_EXTERNAL_STORAGE
+ )
}
}
package jp.osdn.gokigen.mangle
import android.content.ContentResolver
-import android.content.ContentValues
+import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Environment
+import android.provider.DocumentsContract
import android.provider.MediaStore
import androidx.annotation.RequiresApi
import androidx.fragment.app.FragmentActivity
+import androidx.preference.PreferenceManager
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor
import java.io.File
/**
{
try
{
+ val mediaLocation = PreferenceManager.getDefaultSharedPreferences(activity).getString(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION, "")
+ if ((mediaLocation != null)&&(mediaLocation.length > 1))
+ {
+ return
+ }
+
+ val path = Environment.DIRECTORY_DCIM + File.separator + activity.getString(R.string.app_location)
+ val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
+ intent.addCategory(Intent.CATEGORY_OPENABLE)
+ intent.setType("*/*")
+ intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, path)
+ activity.startActivityForResult(
+ Intent(Intent.ACTION_OPEN_DOCUMENT_TREE),
+ MainActivity.REQUEST_CODE_OPEN_DOCUMENT_TREE
+ )
}
catch (e : Exception)
}
}
-
private fun isExternalStorageWritable(): Boolean
{
return (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED)
import androidx.preference.PreferenceManager
import com.google.android.material.snackbar.Snackbar
import jp.osdn.gokigen.mangle.R
-import jp.osdn.gokigen.mangle.StorageOperationWithPermission
import jp.osdn.gokigen.mangle.liveview.storeimage.IStoreImage
import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor
import java.io.File
private val FILENAME_FORMAT = "yyyyMMdd_HHmmss"
private var imageCapture: ImageCapture? = null
- //private lateinit var outputDirectory: File
- //private var isLocalLocation : Boolean = false
-
init
{
}
{
val savedUri = Uri.fromFile(photoFile)
val msg = context.getString(R.string.capture_success) + " $savedUri"
- //Toast.makeText(context.baseContext, msg, Toast.LENGTH_SHORT).show()
+
Snackbar.make(
context.findViewById<androidx.constraintlayout.widget.ConstraintLayout>(
R.id.main_layout
values.put(MediaStore.Images.Media.RELATIVE_PATH, path)
values.put(MediaStore.Images.Media.IS_PENDING, true)
extStorageUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
- //extStorageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
-
values.put(MediaStore.Images.Media.DATA, outputDir.absolutePath + File.separator + photoFile)
}
else
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
{
- Log.v(TAG, " ===== StorageOperationWithPermission() : ${imageUri} =====")
+ Log.v(TAG, " ===== StorageOperationWithPermission() : $imageUri =====")
//StorageOperationWithPermission(context).requestAndroidRMediaPermission(imageUri)
}
)
if (captureBothCamera)
{
- val thread = Thread(Runnable { storeImage.doStore() })
+ val thread = Thread { storeImage.doStore() }
try
{
thread.start()
// --- HIDDEN
const val SHOW_GRID_STATUS = "show_grid"
const val SHOW_GRID_STATUS_DEFAULT_VALUE = false
+ const val EXTERNAL_STORAGE_LOCATION = "external_storage_location"
+ const val EXTERNAL_STORAGE_LOCATION_DEFAULT_VALUE = ""
}
}
package jp.osdn.gokigen.mangle.preference
import android.content.SharedPreferences
+import android.net.Uri
class PreferenceValueInitializer
{
IPreferencePropertyAccessor.CAPTURE_ONLY_LIVE_VIEW_DEFAULT_VALUE
)
}
+ if (!items.containsKey(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION))
+ {
+ editor.putString(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION, IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION_DEFAULT_VALUE)
+ }
editor.apply()
}
+ fun initializeStorageLocationPreferences(preferences: SharedPreferences)
+ {
+ val items : Map<String, *> = preferences.all
+ val editor : SharedPreferences.Editor = preferences.edit()
+ if (!items.containsKey(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION))
+ {
+ editor.putString(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION, IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION_DEFAULT_VALUE)
+ }
+ editor.apply()
+ }
+
+ fun storeStorageLocationPreference(preferences: SharedPreferences, uri : Uri)
+ {
+ try
+ {
+ val editor : SharedPreferences.Editor = preferences.edit()
+ editor.putString(IPreferencePropertyAccessor.EXTERNAL_STORAGE_LOCATION, uri.toString())
+ editor.apply()
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
}
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.0.1'
+ classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong