From 04b1173dc79ae15fca9d89b94bc601ee9106d069 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Jul 2016 15:45:01 +0200 Subject: [PATCH] try opening files too --- .../simplemobiletools/filemanager/Utils.java | 4 ++++ .../filemanager/activities/MainActivity.java | 5 ----- .../filemanager/fragments/ItemsFragment.java | 17 +++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java index 481ff22f..9a4451be 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java @@ -11,6 +11,10 @@ public class Utils { return path.substring(path.lastIndexOf("/") + 1); } + public static String getFileExtension(String fileName) { + return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase(); + } + public static void showToast(Context context, int resId) { Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index 9c4c5533..5ca88a47 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -23,11 +23,6 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); - } - - @Override - protected void onResume() { - super.onResume(); tryInitFileManager(); } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index ffc8f9ae..b2bf9c66 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -1,10 +1,14 @@ package com.simplemobiletools.filemanager.fragments; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.MimeTypeMap; import android.widget.AdapterView; import android.widget.ListView; @@ -70,6 +74,19 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad final FileDirItem item = mItems.get(position); if (item.getIsDirectory()) { mListener.itemClicked(item.getPath()); + } else { + final String path = item.getPath(); + final File file = new File(path); + MimeTypeMap myMime = MimeTypeMap.getSingleton(); + Intent newIntent = new Intent(Intent.ACTION_VIEW); + String mimeType = myMime.getMimeTypeFromExtension(Utils.getFileExtension(path)); + newIntent.setDataAndType(Uri.fromFile(file), mimeType); + newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + try { + startActivity(newIntent); + } catch (ActivityNotFoundException e) { + Utils.showToast(getContext(), R.string.no_app_found); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1a18523a..aa7880b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ Simple File Manager We need the permission to access your storage + No app for opening this type of files is available