2017-04-18 82 views
-3

這下面的代碼是從設備中挑選圖像。如何從設備中選擇PDF,以及如何在圖像視圖中顯示PDF?如何在圖像視圖android中顯示pdf?

bt_gall .setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Intent intent = new Intent(); 
        // Show only images, no videos or anything else 
        intent.setType("image/*"); 
        intent.setAction(Intent.ACTION_GET_CONTENT); 
        // Always show the chooser (if there are multiple options available) 
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); 
        alertDialog.dismiss(); 
       } 
      }); 
+0

'ImageView'不支持打印pdf – snachmsm

+0

'pdf'文件是**不是圖像**。 –

回答

0

要選擇PDF試試這個

Intent intent = new Intent(); 
     intent.setType("application/pdf"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 
     startActivityForResult(Intent.createChooser(intent, "Select PDF"), 1); 

要設置PDF作爲圖像,你需要創建PDF

的縮略圖

生成縮略圖查看這

https://stackoverflow.com/a/38829523/3416642

希望這會幫助你。

+0

在例子中,當我按下按鈕時,我想選擇圖像文件或pdf文件。代碼是什麼? – spodee

+0

@spodee通過多重MIME類型 - 檢查此http://stackoverflow.com/a/33117677/3416642 – Sach

+0

當我嘗試此代碼[意圖意圖=新的意圖(); intent.setType(「image/* | application/pdf」); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(intent,「選擇文檔」),1);]僅圖像選擇。 – spodee