Created
August 5, 2015 02:05
-
-
Save Logan676/37549fe53dea14040100 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Attempts to open a file for viewing. | |
* | |
* @param fileholder The holder of the file to open. | |
*/ | |
public static void openFile(FileHolder fileholder, Context c) { | |
Intent intent = new Intent(android.content.Intent.ACTION_VIEW); | |
Uri data = FileUtils.getUri(fileholder.getFile()); | |
String type = fileholder.getMimeType(); | |
if ("*/*".equals(type)){ | |
intent.setData(data); | |
intent.putExtra(FileManagerIntents.EXTRA_FROM_OI_FILEMANAGER, true); | |
} else { | |
intent.setDataAndType(data, type); | |
} | |
try { | |
List<ResolveInfo> activities = c.getPackageManager().queryIntentActivities(intent, PackageManager.GET_ACTIVITIES); | |
if (activities.size() == 0 || (activities.size() == 1 && c.getApplicationInfo().packageName.equals(activities.get(0).activityInfo.packageName))){ | |
Toast.makeText(c, R.string.application_not_available, Toast.LENGTH_SHORT).show(); | |
return; | |
} else { | |
c.startActivity(intent); | |
} | |
} catch (ActivityNotFoundException e) { | |
Toast.makeText(c.getApplicationContext(), R.string.application_not_available, Toast.LENGTH_SHORT).show(); | |
} catch (SecurityException e){ | |
Toast.makeText(c.getApplicationContext(), R.string.application_not_available, Toast.LENGTH_SHORT).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment