2012-12-07 29 views
0

我嘗試使用意圖操作文件不會打開,但我不能爲PDF和圖片文件文件和圖像文件中的android

對於圖像所有的應用程序要崩潰(包括庫的應用程序)

對DOC/DOCX我使用的辦公套件,但給出了包(了java.lang.RuntimeException)運行時異常。請參閱下面的代碼:

Intent intent = new Intent(); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.setAction(Intent.ACTION_VIEW); 

if (extension.equalsIgnoreCase("jpg") 
        | extension.equalsIgnoreCase("jpeg") 
        | extension.equalsIgnoreCase("png") 
        | extension.equalsIgnoreCase("bitmap")) { 
       intent.setDataAndType(Uri.parse(fileName), "image/*"); 
      } else if (extension.equalsIgnoreCase("xml") 
        | extension.equalsIgnoreCase("txt") 
        | extension.equalsIgnoreCase("csv")) { 
       intent.setDataAndType(Uri.parse(fileName), "text/*"); 
      } else if (extension.equalsIgnoreCase("mp4") 
        | extension.equalsIgnoreCase("3gp")) { 
       intent.setDataAndType(Uri.parse(fileName), "video/*"); 
      } else if (extension.equalsIgnoreCase("pdf")) { 
       intent.setDataAndType(Uri.parse(fileName), "application/pdf"); 

       System.out.println("Pdf file to open "+fileName); 

      } else if (extension.equalsIgnoreCase("doc") 
        | extension.equalsIgnoreCase("docx")) { 

       intent.setDataAndType(Uri.parse(fileName), "application/word"); 

      } 


      context.startActivity(intent); 

但是,如果我試圖通過去文件資源管理器打開這些文件都正確打開文件。

+0

您可以發佈您的例外/ logcat的? –

+0

當我試圖打開文檔/ docx文件與辦公套件Office套件給消息丟失
任何人都可以知道如何刪除它? –

回答

0

我認爲它的文件URI類的問題沒有返回文件 我發現錯誤

這是Uri.parse(文件名)

我現在用Uri.fromFile(文件名)其工作現在。

1

試試這個:

Intent intent = new Intent(Intent.ACTION_VIEW); 

     //intent.setAction(Intent.ACTION_VIEW); 

     if (extension.equalsIgnoreCase("jpg") 
       | extension.equalsIgnoreCase("jpeg") 
       | extension.equalsIgnoreCase("png") 
       | extension.equalsIgnoreCase("bitmap")) { 
      intent.setDataAndType(Uri.parse("file://"+fileName), "image/*"); 
     } else if (extension.equalsIgnoreCase("xml") 
       | extension.equalsIgnoreCase("txt") 
       | extension.equalsIgnoreCase("csv")) { 
      intent.setDataAndType(Uri.parse("file://"+fileName), "text/*"); 
     } else if (extension.equalsIgnoreCase("mp4") 
       | extension.equalsIgnoreCase("3gp")) { 
      intent.setDataAndType(Uri.parse("file://"+fileName), "video/*"); 
     }else if(extension.equalsIgnoreCase("pdf")){ 
      intent.setDataAndType(Uri.parse("file://"+fileName), "application/pdf"); 
     }else if(extension.equalsIgnoreCase("doc") 
       | extension.equalsIgnoreCase("docx")){ 
      intent.setDataAndType(Uri.parse("file://"+fileName), "text/*"); 
     } 
     // else 
     // if(extension.equalsIgnoreCase("mp3")|extension.equalsIgnoreCase("amr")|extension.equalsIgnoreCase("wav")){ 
     // intent.setDataAndType(Uri.parse(fileName), "audio/mp3"); 
     // } 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     context.startActivity(intent);