diff --git a/app/build.gradle b/app/build.gradle index 0efef98..883ba1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,7 +25,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.2' - implementation "androidx.activity:activity:1.1.0" + implementation "androidx.activity:activity-ktx:1.2.0-beta01" + implementation 'androidx.fragment:fragment-ktx:1.3.0-beta01' androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 183d256..b8e7f62 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,11 +10,12 @@ + android:theme="@style/Theme.AppCompat"> + if (isGranted) { + // Permission is granted. Continue the action or workflow in your + // app. + } else { + // Explain to the user that the feature is unavailable because the + // features requires a permission that the user has denied. At the + // same time, respect the user's decision. Don't link to system + // settings in an effort to convince the user to change their + // decision. + } + } + + val sdcardFile = Environment.getExternalStorageDirectory() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) main_btn_start.setOnClickListener { var text = etPath.text.toString() - if (text.isEmpty()) text = "/sdcard/Android/data/com.nomansland.tempestwave/files/" + if (text.isEmpty()) text = File(sdcardFile, "Android/data/com.nomansland.tempestwave/files/").canonicalPath val i = Intent(this@MainActivity, DifficultySelectionActivity::class.java) i.putExtra("path", text) this@MainActivity.startActivity(i) @@ -24,7 +47,29 @@ class MainActivity : Activity() { val i = Intent(this@MainActivity, AboutActivity::class.java) this@MainActivity.startActivity(i) } + when { + ContextCompat.checkSelfPermission( + applicationContext, + Manifest.permission.READ_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED -> { + // You can use the API that requires the permission. + } + else -> { + // You can directly ask for the permission. + // The registered ActivityResultCallback gets the result of this request. + requestPermissionLauncher.launch( + Manifest.permission.READ_EXTERNAL_STORAGE) + } + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { + if (!Environment.isExternalStorageManager()) { + startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)) + } + } else { +// TODO("VERSION.SDK_INT < R") + + } // requestPermission } } \ No newline at end of file