Skip to content

Commit

Permalink
Merge pull request #15 from daschfg/main
Browse files Browse the repository at this point in the history
Implement workaround for issue #14
  • Loading branch information
Tiim authored Oct 27, 2023
2 parents bf9849d + a80cb74 commit 0bf8637
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.webkit.MimeTypeMap
import android.widget.EditText
import android.widget.RadioGroup
import android.widget.RemoteViews
Expand All @@ -34,10 +35,18 @@ class MarkdownFileWidgetConfigureActivity : Activity() {
private lateinit var inputFilePath: EditText
private lateinit var radioGroup: RadioGroup
private val onBrowse = View.OnClickListener {
// Workaround for https://github.com/Tiim/Android-Markdown-Widget/issues/14:
// Check if MIME-Type "text/markdown" is known. Otherwise fall back to
// generic type to still allow file selection.
val mimetype = if (MimeTypeMap.getSingleton().hasMimeType("text/markdown")) {
"text/markdown"
} else {
"*/*"
}
// https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/markdown"
type = mimetype
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION.or( Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
}
startActivityForResult(Intent.createChooser(intent, "Select a markdown file"), ACTIVITY_RESULT_BROWSE)
Expand Down

0 comments on commit 0bf8637

Please sign in to comment.