Skip to content

Commit

Permalink
android app: ask permission in the application, not widget
Browse files Browse the repository at this point in the history
opsie
  • Loading branch information
Toni500github committed Dec 12, 2024
1 parent 2c1a74c commit 09fcd4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.toni.customfetch_android

import android.app.AlertDialog
import android.content.Intent
import android.content.res.AssetManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -22,6 +27,25 @@ class SettingsActivity : AppCompatActivity() {
.commit()
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager()) {
AlertDialog.Builder(this)
.setTitle("Grant external storage management permission")
.setMessage("Customfetch needs permissions to manage external storage for writing config files\n"+
"By default we going to read/write the following directories:\n"+
"/storage/emulated/0/.config/\n"+
"/storage/emulated/0/.config/customfetch/")
// The dialog is automatically dismissed when a dialog button is clicked.

.setPositiveButton("Grant permission"
) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
startActivity(intent)
}
.setIcon(android.R.drawable.ic_dialog_alert)
.show()
}
}
}

class SettingsFragment : PreferenceFragmentCompat() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.toni.customfetch_android.widget

import android.app.Activity
import android.app.AlertDialog
import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextPaint
Expand Down Expand Up @@ -64,26 +60,6 @@ class customfetchConfigureActivity : Activity() {
binding = CustomfetchConfigureBinding.inflate(layoutInflater)
setContentView(binding.root)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
AlertDialog.Builder(this)
.setTitle("Grant external storage management permission")
.setMessage("Customfetch needs permissions to manage external storage for writing config files\n"+
"By default we going to read/write the following directories:\n"+
"/storage/emulated/0/.config/\n"+
"/storage/emulated/0/.config/customfetch/")
// The dialog is automatically dismissed when a dialog button is clicked.

.setPositiveButton("Grant permission"
) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
startActivity(intent)
}
.setIcon(android.R.drawable.ic_dialog_alert)
.show()
}
}

if (!Files.exists(Path(filesDir.absolutePath + "ascii")))
copyToAssetFolder(assets, filesDir.absolutePath, "ascii")

Expand Down

0 comments on commit 09fcd4b

Please sign in to comment.