try opening files too

This commit is contained in:
tibbi 2016-07-13 15:45:01 +02:00
parent b8d517d3dc
commit 04b1173dc7
4 changed files with 22 additions and 5 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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);
}
}
}

View File

@ -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>