mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	try opening files too
This commit is contained in:
		| @@ -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(); | ||||
|     } | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| <resources> | ||||
|     <string name="app_name">Simple File Manager</string> | ||||
|     <string name="no_permissions">We need the permission to access your storage</string> | ||||
|     <string name="no_app_found">No app for opening this type of files is available</string> | ||||
| </resources> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user