2012-03-29 3 views
1

내 애플 리케이션 downlods PDF 파일 링크를 SD 카드에 저장하고, 그것은 잘하고있어 ..하지만 내가 뭘 고군분투 해요 내 애플 리케이션은 PDF 파일을 볼 수 없어 (내 에뮬레이터에서 PDF 뷰어를 설치 한하지만) ... 아무것도 파일을 다운로드 한 후 반응이 없습니다 ... 여기에 pdf 파일을 열려면 pdf 파일을 코드 아래내 애플 리케이션이 PDF 파일을 엽니 다

        InputStream input = new BufferedInputStream(url.openStream()); 
      File sdCard = Environment.getExternalStorageDirectory(); 
      File dir = new File(sdCard.getAbsolutePath() 
        + "/myapp/download"); 
      dir.mkdirs(); 
      File file = new File(dir, "application/pdf"); 
      FileOutputStream output = new FileOutputStream(file); 
+1

게시하기 전에 검색하십시오. [읽기이] (http://stackoverflow.com/questions/2456344/display-pdf-within-app-on-android) 및 [This (http://stackoverflow.com/questions/1697726/how-to- pdf-and-read-it) – Calvin

답변

2

사용 열리는 내 코드입니다. yourActivityClass.this

File pdfFile = new File("/mnt/sdcard/path_to_file/yourpdf.pdf"); 
    if(pdfFile.exists()) { 
     Uri path = Uri.fromFile(pdfFile); 
     Intent pdfIntent = new Intent(Intent.ACTION_VIEW); 
     pdfIntent.setDataAndType(path, "application/pdf"); 
     pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     try { 
      startActivity(pdfIntent); 
     } catch(ActivityNotFoundException e) { 
      Toast.makeText(yourActivityClass.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
     } 
    } else { 
     Toast.makeText(yourActivityClass.this, "File not found", Toast.LENGTH_LONG).show(); 
    } 

은 위의 코드를 테스트하는 동안 애플리케이션 컨텍스트가 올바른지 확인합니다.

+0

감사합니다. – AliDeV

관련 문제