mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 03:11:30 +00:00
Send an alternative intent on folder open (fixes #838)
This commit is contained in:
parent
299b556923
commit
f6f09515c5
2 changed files with 15 additions and 1 deletions
|
@ -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<Folder> {
|
||||
|
||||
private static final String TAG = "FoldersAdapter";
|
||||
|
||||
private final HashMap<String, Model> mModels = new HashMap<>();
|
||||
|
||||
public FoldersAdapter(Context context) {
|
||||
|
@ -53,11 +56,20 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
|
|||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ Please report any problems you encounter via Github.</string>
|
|||
<item quantity="other">%1$d / %2$d Files</item>
|
||||
</plurals>
|
||||
|
||||
<string name="open_file_manager">Open file manager</string>
|
||||
|
||||
<string name="toast_no_file_manager">No compatible file manager found</string>
|
||||
|
||||
<!-- DevicesFragment -->
|
||||
|
|
Loading…
Reference in a new issue