멍멍이네 블로그

다른 블로그들 참고하는데 안되다가 되는 블로그 발견!

file = File 클래스 변수임(안나와있는데 대충 File클래스 메소드를 사용하길래 해당 자료형의 변수로 선언했더니 잘됨.

참고로 파일에 해당하는 뷰어나 볼 수 있는 프로그램이 있어야됨.

 

  Intent intent = new Intent();
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setAction(android.content.Intent.ACTION_VIEW);
  intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  if (file.getName().endsWith(".pdf")){

 intent.setDataAndType(Uri.fromFile(file), "application/pdf");
  }else if (file.getName().endsWith(".hwp")){
intent.setDataAndType(Uri.fromFile(file), "application/hwp");
  }
  try{
   startActivity(intent);
  }catch(ActivityNotFoundException e){
   util.showLongToast("해당파일을 실항할 수 있는 어플리케이션이 없습니다.\n파일을 열 수 없습니다.");
   e.printStackTrace();
  }

 

pdf = "application/pdf"

jpg 등 = "image/*"

docx = "application/msword"

txt = "text"

pptx = "application/vnd.ms-powerpoint"

hwp = "application/haansofthwp"

mp3 = "audio/*"

mp4 = "video/*"

 

 

...

 

mineType 안헷갈리게 조심!

 

 

출처 : http://ldelight.tistory.com/20

확장자 출처 : http://anditstory.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%ED%8C%8C%EC%9D%BC-%EC%97%B0%EA%B2%B0-Intent-setDataAndTypeUri-MimeType