5

Hiện tại tôi đang cố gắng chọn loại tệp cụ thể từ thẻ SD hoặc với bất kỳ ứng dụng nào nhưng không thành công, mã của tôi như sau,Chọn docx, doc, rtf, pdf loại tệp từ thẻ SD hoặc với bất kỳ ứng dụng nào trong android

Intent intent; 
     if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) 
      intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 
     else 
      intent = new Intent(Intent.ACTION_GET_CONTENT); 

     intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
     intent.addCategory(Intent.CATEGORY_OPENABLE); 
     intent.setType("application/pdf|application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document" + 
       "|application/vnd.openxmlformats-officedocument.wordprocessingml.template" + 
       "|application/vnd.ms-word.document.macroEnabled.12" + 
       "|application/vnd.ms-word.template.macroEnabled.12" + 
       "!application/vnd.ms-word.template.macroEnabled.12|application/rtf"); 

     startActivityForResult(intent, Constants.ImagePicker.REQ_PICK_RESUME); 

nhưng nó chỉ chọn mọi loại tệp.

+0

thể trùng lặp của https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in-android – k3b

+0

Có thể trùng lặp [cách chọn vài loại tệp thông qua ý định trong android?] (Https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in -android) – k3b

Trả lời

0

thử mã này:

Intent intent = new Intent(); 
intent.setType("application/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent, "Select file"),1); 
+0

@i phải chọn loại tệp cụ thể không phải là toàn bộ, nếu không có ứng dụng nào được cài đặt để xử lý loại tệp rtf thì sao ?? – TheReprator

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