2011-09-07 71 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

好了完成谢谢 – kshma