[¾Èµå·ÎÀ̵å]ÆÄÀÏ ¿¬°á - Intent setDataAndType(Uri , MimeType) |
|
|
![](icon/private_name/1.gif) |
8³â Àü |
/**
* ÆÄÀÏÀÇ È®ÀåÀÚ Á¶È¸
*
* @param fileStr
* @return
*/
public static String getExtension(String fileStr) {
return fileStr.substring(fileStr.lastIndexOf(".") + 1, fileStr.length());
}
/**
* Viewer·Î ¿¬°á
*
* @param ctx
* @param filePath
* @param fileName
*/
public static void viewFile(Context ctx, String filePath, String fileName) {
// TODO Auto-generated method stub
Intent fileLinkIntent = new Intent(Intent.ACTION_VIEW);
fileLinkIntent.addCategory(Intent.CATEGORY_DEFAULT);
File file = new File(filePath, fileName);
Uri uri = Uri.fromFile(file);
//È®ÀåÀÚ ±¸Çϱâ
String fileExtend = getExtension(file.getAbsolutePath());
// ÆÄÀÏ È®ÀåÀÚ º°·Î mime type ÁöÁ¤ÇØ ÁØ´Ù.
if (fileExtend.equalsIgnoreCase("mp3")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "audio/*");
} else if (fileExtend.equalsIgnoreCase("mp4")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "vidio/*");
} else if (fileExtend.equalsIgnoreCase("jpg")
|| fileExtend.equalsIgnoreCase("jpeg")
|| fileExtend.equalsIgnoreCase("gif")
|| fileExtend.equalsIgnoreCase("png")
|| fileExtend.equalsIgnoreCase("bmp")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "image/*");
} else if (fileExtend.equalsIgnoreCase("txt")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "text/*");
} else if (fileExtend.equalsIgnoreCase("doc")
|| fileExtend.equalsIgnoreCase("docx")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "application/msword");
} else if (fileExtend.equalsIgnoreCase("xls")
|| fileExtend.equalsIgnoreCase("xlsx")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file),
"application/vnd.ms-excel");
} else if (fileExtend.equalsIgnoreCase("ppt")
|| fileExtend.equalsIgnoreCase("pptx")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file),
"application/vnd.ms-powerpoint");
} else if (fileExtend.equalsIgnoreCase("pdf")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file), "application/pdf");
} else if (fileExtend.equalsIgnoreCase("hwp")) {
fileLinkIntent.setDataAndType(Uri.fromFile(file),
"application/haansofthwp");
}
PackageManager pm = ctx.getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(fileLinkIntent,
PackageManager.GET_META_DATA);
if (list.size() == 0) {
Toast.makeText(ctx, fileName + "À» È®ÀÎÇÒ ¼ö ÀÖ´Â ¾ÛÀÌ ¼³Ä¡µÇÁö ¾Ê¾Ò½À´Ï´Ù.",
Toast.LENGTH_SHORT).show();
} else {
ctx.startActivity(fileLinkIntent);
}
} |
|
̵̧ : 359 |
̵̧
¸ñ·Ï
|
|