2014-03-25 3 views
2

내 화면 헤더 레이블에는 화면의 하단에있는 버튼 하나가 있습니다. 이 라벨 과이 버튼을 구현하는 방법 사이에 PDF 파일을 표시하고 싶습니다. PDF를 열려고 할 때 화면 공간이 전체 입니다.안드로이드에서 화면의 특정 영역에 PDF 파일을 여는 방법

 File file = new File(getFilesDir(), "mypdf.pdf"); 


     try { 
      fis = new FileInputStream(file); 
     } catch (FileNotFoundException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     //System.out.println(file.exists() + "!!"); 
     //InputStream in = resource.openStream(); 
     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     byte[] buf = new byte[1024]; 
     try { 
      for (int readNum; (readNum = fis.read(buf)) != -1;) { 
       bos.write(buf, 0, readNum); //no doubt here is 0 
       //Writes len bytes from the specified byte array starting at offset off to this byte array output stream. 
       System.out.println("read " + readNum + " bytes,"); 
      } 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } 
     byte[] bytes = bos.toByteArray(); 

     //below is the different part 
     File someFile = new File("java2.pdf"); 
     try { 
      FileOutputStream fos = new FileOutputStream(someFile); 
      fos.write(bytes); 
      fos.flush(); 
      fos.close(); 
     } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(
       Uri.parse("file://" + getFilesDir() + "/java2.pdf"), 
       "application/pdf"); 

     startActivity(intent); 

답변

0

필자는 시도하지 않았지만 PDF를 표시하려는 Ativity에서 조각을 사용해야합니다. 원래 위치에서 :

Fragments

단편 행동 또는 활성 사용자 인터페이스의 일부를 나타낸다. 단일 활동에서 여러 단편을 결합하여 다중 창 UI를 작성하고 여러 활동에서 단편을 재사용 할 수 있습니다.

단추와 머리글 사이에 단일 조각을 사용하고 PDF를 엽니 다. 어쩌면 그것은 당신을 도울 것입니다

+0

파편에 나는 어떻게 그것의 자신의 콘테이너에있는 pdf 열리기 때문에 pdf를 보여줄 것인가? 내 UI에서 그것을 PDF 컨테이너에 표시하고 싶습니다. –

+0

@MDFAIZANWAR 문제는이 호출을 통해 외부 응용 프로그램에 PDF 애 퍼처가 필요하다는 것입니다. Intent intent = new Intent (Intent.ACTION_VIEW); 그래서 사용자 정의보기를 easly 처리 할 수 ​​없습니다. – MatteoM

관련 문제