을 열고 난 당신이 의도이를 위해 만들어진 ...이 경로를해야 할 이유가 표시되지 않습니다이
private void openFile(File f)
{
// Create an Intent
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
// Category where the App should be searched
// String category = new String("android.intent.category.DEFAULT");
// Setting up the data and the type for the intent
String type = getMIMEType(f);
/*Uri startDir = Uri.fromFile(f);
intent.setAction(Intent.ACTION_PICK);
intent.setDataAndType(startDir, "vnd.android.cursor.dir/*");*/
intent.setDataAndType(Uri.fromFile(f), type);
// will start the activtiy found by android or show a dialog to select one
startActivity(intent);//
/**intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK+Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
String theMIMEcategory = getMIMEcategory(type);
intent.setDataAndType(Uri.fromFile(f),theMIMEcategory);
try {
startActivity(Intent.createChooser(intent,"Choose Applicaton"));
} catch (Exception e) {
//show error
}
*/
}
/**
* Returns the MIME type for the given file.
*
* @param f the file for which you want to determine the MIME type
* @return the detected MIME type
*/
private String getMIMEType(File f)
{
String end = f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length()).toLowerCase();
String type = "";
if(end.equals("mp3") || end.equals("aac") || end.equals("aac") || end.equals("amr") || end.equals("mpeg") || end.equals("mp4")) type = "audio/*";
else if(end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg")) type = "image/*";
else if(end.equals("pdf")) type = "application/pdf";
else if(end.equals("xls")) type = "application/vnd.ms-excel";
else if(end.equals("doc")) type = "application/msword";
else if(end.equals("zip")) type="application/zip";
else {type="*/*" ;}
//type += "/*";
return type;
}
public static String getMIMEcategory(String aMIMEtype) {
if (aMIMEtype!=null) {
aMIMEtype = aMIMEtype.substring(0,aMIMEtype.lastIndexOf("/",aMIMEtype.length()-1))+"/*";
} else {
aMIMEtype = "*/*";
}
return aMIMEtype;
}'
출처
2011-04-07 08:16:14
Mak
을하려면 다음 코드를 사용했다. – ykatchou
좋아, 나는 의도가이 모든 것을 만들 수 있다는 것을 몰랐다. – Mak