Skip to content

Commit

Permalink
fix: Removed support for file:// URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Nov 5, 2022
1 parent 5470b49 commit e1f5260
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CharSequence>(
getString(R.string.intent_import_mode_add),
getString(R.string.intent_import_mode_select)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class FileLibraryDialogFragment : ListPreferenceDialogFragmentCompat() {
StorageUtils.queryName(
requireContext(),
uri
)
) ?: "INVALID"
)
if(!correctType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,6 @@
<string name="intent_import_fail">Failed to import file \'%1$s\'</string>
<string name="intent_import_success">File \'%1$s\' imported</string>
<string name="intent_import_select_success">File \'%1$s\' imported and activated</string>
<string name="intent_import_error_file_uri">Failed to import file. Unsupported file URI.</string>

</resources>

0 comments on commit e1f5260

Please sign in to comment.