2012-05-24 17 views
5

Tôi có ứng dụng trong đó người dùng có thể tìm kiếm hình ảnh, âm thanh, video, tệp doc từ sdcard và chọn 1 tệp để tải lên trên máy chủ. Sử dụng mã Dưới đây tôi có thể mở thư viện và chọn hình ảnh, âm thanh, video Nhưng tôi không biết cách tìm kiếm tài liệu từ thư viện.Android Làm thế nào để xem tài liệu từ sdcard trong gallary?

Đây là mã của tôi.

Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    //intent.setType("video/*"); 
    //intent.setType("audio/*"); 
    //intent.setType("image/*"); 
    //**What I have to do for view document[.pdf/text/doc] file** 
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE); 

Có ai có ý tưởng nào về điều này có thể đạt được không? Bất kỳ trợ giúp nào cũng được đánh giá rất cao.

Trả lời

0

Hy vọng điều này sẽ giúp bạn mở một tài liệu

public void openDOC(String name) { 


     File file = new File(Environment.getExternalStorageDirectory() + "/" 
       + bmodel.getUserMasterBO().getUserid() + "/" + name); 
     if (file.exists()) { 
      Uri path = Uri.fromFile(file); 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(path, "application/msword"); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

      try { 
       startActivity(intent); 
      } catch (ActivityNotFoundException e) { 
       Toast.makeText(this, "No Application Available to View DOC", 
         Toast.LENGTH_SHORT).show(); 
      } 
     } 

    } 
+0

Cảm ơn bạn đã swer. Tôi muốn xem tất cả các tập tin và hơn sau khi tôi sẽ chọn danh sách biểu mẫu tập tin duy nhất. Tôi không muốn mở tài liệu. Tôi chỉ cần một con đường để tôi có thể tải nó lên máy chủ. – Nik88

0

Hãy thử những điều sau đây,

File docfolder = new File(Environment.getExternalStorageDirectory() + "/" 
       + "Documents/"); 
File docList[] = docfolder.listFiles(); 
for(int i=0;i<docList.length;i++) 
{ 
     if (docList[i].exists()) { 
      Uri path = Uri.fromFile(docList[i]); 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(path, "application/msword"); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

      try { 
       startActivity(intent); 
      } 
      catch (ActivityNotFoundException e) { 

      } 
     } 
} 
1

thử thư viện này aFileChooser làm việc tốt

pls nó thấy link này

Các vấn đề liên quan