try a more generic mime type if a file cannot be open by anything

This commit is contained in:
tibbi 2016-07-13 23:13:57 +02:00
parent 9c40031300
commit 98b4710b36
1 changed files with 22 additions and 1 deletions

View File

@ -113,17 +113,38 @@ public class ItemsFragment extends android.support.v4.app.Fragment
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Utils.showToast(getContext(), R.string.no_app_found);
if (!tryGenericMimeType(intent, mimeType, file)) {
Utils.showToast(getContext(), R.string.no_app_found);
}
}
}
}
private boolean tryGenericMimeType(Intent intent, String mimeType, File file) {
final String genericMimeType = getGenericMimeType(mimeType);
intent.setDataAndType(Uri.fromFile(file), genericMimeType);
try {
startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}
@Override
public void onRefresh() {
fillItems();
mSwipeRefreshLayout.setRefreshing(false);
}
private String getGenericMimeType(String mimeType) {
if (!mimeType.contains("/"))
return mimeType;
final String type = mimeType.substring(0, mimeType.indexOf("/"));
return type + "/*";
}
public interface ItemInteractionListener {
void itemClicked(String path);
}