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);
파편에 나는 어떻게 그것의 자신의 콘테이너에있는 pdf 열리기 때문에 pdf를 보여줄 것인가? 내 UI에서 그것을 PDF 컨테이너에 표시하고 싶습니다. –
@MDFAIZANWAR 문제는이 호출을 통해 외부 응용 프로그램에 PDF 애 퍼처가 필요하다는 것입니다. Intent intent = new Intent (Intent.ACTION_VIEW); 그래서 사용자 정의보기를 easly 처리 할 수 없습니다. – MatteoM