try a more generic mime type if a file cannot be open by anything
This commit is contained in:
parent
9c40031300
commit
98b4710b36
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue