2011-09-07 1 views
0
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 
    Button OpenPDF = (Button) findViewById(R.id.button); 
    OpenPDF.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      File pdfFile = new File("res/raw/comic.pdf"); 
      if(pdfFile.exists()) 
      { 
       //Uri path = Uri.fromFile(pdfFile); 
      Uri path = Uri.parse("android.resource://" + getPackageName() + "/ R.raw.comic.pdf"); 

       Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setDataAndType(path, "application/pdf"); 
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

       // Intent pdfIntent = new Intent(Intent.ACTION_VIEW); 
       // Intent pdfIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://package.name/" + pdfFile)); 
       // pdfIntent.setDataAndType(path, "/assets/arduino-comic-latest.pdf"); 
       // pdfIntent.setType("application/pdf"); 
       // pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       try 
       { 
        startActivity(intent); 
       } 
       catch(ActivityNotFoundException e) 
       { 
        Toast.makeText(MainActivity.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
       } 
      } 

     } 
    }); 

코딩을 통해 안드로이드를 통해 읽을 수는 있지만 이것이 내가해야하는 file.what의 경로를 찾을 수 없습니다되는 방법?이 사람은 나를는 PDF 파일이 코드를 수행 한

감사합니다

을 도울 수

답변

2

당신은 그것을 직접 할 수 없습니다. PDF를 읽으려면 네이티브 라이브러리를 사용해야합니다 ... 도서관은 iText, jPedal, Mupdf, Pdfbox ... 등이 될 수 있습니다. Google

+0

okit가 완료되었습니다. – kshma

관련 문제