From f6f09515c550e169979f95a4dff3c68ce621d134 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Fri, 27 Apr 2018 23:52:53 +0200 Subject: [PATCH] Send an alternative intent on folder open (fixes #838) --- .../syncthingandroid/views/FoldersAdapter.java | 14 +++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java index 03ff67a1..3c359ac7 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java @@ -7,6 +7,7 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -33,6 +34,8 @@ import static android.view.View.VISIBLE; */ public class FoldersAdapter extends ArrayAdapter { + private static final String TAG = "FoldersAdapter"; + private final HashMap mModels = new HashMap<>(); public FoldersAdapter(Context context) { @@ -53,11 +56,20 @@ public class FoldersAdapter extends ArrayAdapter { binding.openFolder.setOnClickListener(v -> { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(folder.path)), "resource/folder"); + intent.putExtra("org.openintents.extra.ABSOLUTE_PATH", folder.path); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(getContext().getPackageManager()) != null) { getContext().startActivity(intent); } else { - Toast.makeText(getContext(), R.string.toast_no_file_manager, Toast.LENGTH_SHORT).show(); + // Try a second way to find a compatible file explorer app. + Log.v(TAG, "openFolder: Fallback to application chooser to open folder."); + intent.setDataAndType(Uri.parse(folder.path), "application/*"); + Intent chooserIntent = Intent.createChooser(intent, getContext().getString(R.string.open_file_manager)); + if (chooserIntent != null) { + getContext().startActivity(chooserIntent); + } else { + Toast.makeText(getContext(), R.string.toast_no_file_manager, Toast.LENGTH_SHORT).show(); + } } }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index acd1523c..e0949c20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,8 @@ Please report any problems you encounter via Github. %1$d / %2$d Files + Open file manager + No compatible file manager found