diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d7e4c4f7b..1d8b874fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -58,7 +58,6 @@ - diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/activity/MainActivity.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/activity/MainActivity.kt index 65cc6f3e9..3182854c3 100644 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/activity/MainActivity.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/activity/MainActivity.kt @@ -487,6 +487,11 @@ class MainActivity : BaseActivity() { private fun handleFileIntent(uri: Uri) { val name = StorageUtils.queryName(this, uri) + if (name == null) { + Toast.makeText(this, getString(R.string.intent_import_error_file_uri), Toast.LENGTH_LONG).show() + return + } + val choices = arrayOf( getString(R.string.intent_import_mode_add), getString(R.string.intent_import_mode_select) diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt index 9564031b9..9706f0086 100755 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt @@ -327,7 +327,7 @@ class FileLibraryDialogFragment : ListPreferenceDialogFragmentCompat() { StorageUtils.queryName( requireContext(), uri - ) + ) ?: "INVALID" ) if(!correctType) { diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/utils/StorageUtils.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/utils/StorageUtils.kt index 2ba451bd0..87b4dcfe8 100644 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/utils/StorageUtils.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/utils/StorageUtils.kt @@ -11,10 +11,16 @@ import java.io.InputStream object StorageUtils { fun importFile(context: Context, targetDir: String, uri: Uri): File? { + val name = queryName(context, uri) + if(name == null) { + Timber.e("importFile: name is null") + return null + } + val destinationFilename = File( targetDir + File.separatorChar + - queryName(context, uri) + name ) try { context.contentResolver.openInputStream(uri)?.use { ins -> @@ -57,8 +63,9 @@ object StorageUtils { return true } - fun queryName(context: Context, uri: Uri): String { - val returnCursor = context.contentResolver.query(uri, null, null, null, null)!! + fun queryName(context: Context, uri: Uri): String? { + val returnCursor = context.contentResolver.query(uri, null, null, null, null) + returnCursor ?: return null val nameIndex: Int = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) returnCursor.moveToFirst() val name: String = returnCursor.getString(nameIndex) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47a2ca884..46dcee6f3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -456,5 +456,6 @@ Failed to import file \'%1$s\' File \'%1$s\' imported File \'%1$s\' imported and activated + Failed to import file. Unsupported file URI. \ No newline at end of file