내 Android 앱에 다른 파일을 표시 할 때 오류 발생

SaTech

내 안드로이드 앱에 다른 유형의 파일을 표시하려고하는데 PDF 파일에서만 작동하고 다른 유형의 파일을 표시하려고 할 때만 작동했습니다. 다음과 같은 오류가 발생합니다.

PDF를 표시 할 수 없습니다. 잘못된 파일 형식입니다.

다음은 내 코드의 일부입니다.

  else if (currentFile.toString().contains(".pdf")) {

  String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(".PDF");
  Intent intent = new Intent();
  intent.setAction(android.content.Intent.ACTION_VIEW);
  intent.setDataAndType(Uri.fromFile(currentFile), mime);
  startActivityForResult(intent, 10);

} else if (currentFile.toString().contains(".doc")||currentFile.toString().contains(".docx")) {

  String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(".doc");

  Intent intent = new Intent();
  intent.setAction(android.content.Intent.ACTION_VIEW);
  intent.setDataAndType(Uri.fromFile(currentFile), mime);
  startActivityForResult(intent, 10);

} else if (currentFile.toString().contains(".jpg") || currentFile.toString().contains(".jpeg") || currentFile.toString().contains(".png")){
   String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(".jpg");

  Intent intent = new Intent();
  intent.setAction(android.content.Intent.ACTION_VIEW);
  intent.setDataAndType(Uri.fromFile(currentFile), mime);
  startActivityForResult(intent, 10);
}
SaTech

직접 솔루션을 찾을 수 있으며 여기에 내가 사용한 코드 스 니펫이 있습니다.

private void openFile(File currentFile, String fileFormat) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(currentFile),fileFormat);
    startActivity(intent);
}

이 방법을 다음과 같이 호출했습니다.

...........

                } else if (currentFile.toString().contains(".pdf"))
                openFile(currentFile,"application/pdf");

             else if (currentFile.toString().contains(".doc") || currentFile.toString().contains(".docx"))
                openFile(currentFile,"application/msword");

             else if (currentFile.toString().contains(".jpg") ||
                    currentFile.toString().contains(".jpeg") || currentFile.toString().contains(".png"))
                openFile(currentFile,"image/jpeg");
             else if(currentFile.toString().contains(".ppt") || currentFile.toString().contains(".pptx"))
                 // Powerpoint file
                openFile(currentFile,"application/vnd.ms-powerpoint");
             else if(currentFile.toString().contains(".xls") || currentFile.toString().contains(".xlsx"))
                // Excel file
                openFile(currentFile, "application/vnd.ms-excel");
              else if(currentFile.toString().contains(".zip") || currentFile.toString().contains(".rar"))
                // WAV audio file
                openFile(currentFile,"application/x-wav");

             else if(currentFile.toString().contains(".rtf"))
                // RTF file
                openFile(currentFile,"application/rtf");

             else if(currentFile.toString().contains(".wav") || currentFile.toString().contains(".mp3"))
                // WAV audio file
                openFile(currentFile,"audio/x-wav");

             else if(currentFile.toString().contains(".gif"))
                // GIF file
                openFile(currentFile,"image/gif");
             else if(currentFile.toString().contains(".txt"))
                // Text file
                openFile(currentFile,"text/plain");

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

.dll을 다시 컴파일 할 때 발생하는 오류

분류에서Dev

Android에서 Mandrill SMTP로 이메일을 보내려고 할 때 오류 발생

분류에서Dev

다른 폴더에서 내 C ++ 프로그램을 컴파일 할 때 실행 파일에서 분할 오류가 발생합니다.

분류에서Dev

URL이있는 파일을 내부 저장소 Android Studio로 다운로드 할 때 오류 발생

분류에서Dev

내 저장소에 파일을 추가하려고 할 때 Git에서 readlink 오류가 발생합니다.

분류에서Dev

내 웹 사이트에서 파일을 업로드 할 때이 오류가 발생합니다.

분류에서Dev

데이터 배열을 JTable에 표시 할 때 오류 발생

분류에서Dev

다른 Android 앱으로 파일을 전달할 때 발생하는 문제

분류에서Dev

Google Play에서 내 앱을 테스트 할 때이 오류가 발생했습니다.

분류에서Dev

내 Android 앱에 모듈을 추가 할 때 DuplicateFileException 발생

분류에서Dev

내 프로젝트에 게시물을 업로드하려고 할 때 405 오류가 발생합니다.

분류에서Dev

내 데이터베이스에서 게시물을 검색 할 때 오류가 발생했습니다.

분류에서Dev

다른 함수 내에서 promise 함수를 호출 할 때 오류 발생

분류에서Dev

한 앱을 다른 앱의 데이터베이스에 연결할 때 오류 발생

분류에서Dev

zip 파일에서 파일을 추출 할 때 오류 발생

분류에서Dev

Flutter에서 다운로드에 파일을 저장할 때 오류 발생

분류에서Dev

내가 실행할 때마다 앱에서 Gmail 로그인 통합을 시도 할 때마다 동일한 오류가 표시됩니다.

분류에서Dev

Python-파일에서 바이트 추출을 시도 할 때 오류 발생

분류에서Dev

Linux 서버의 flask에서 파일을 다운로드 할 때 오류 발생

분류에서Dev

시뮬레이터에서 Flutter 앱을 시작할 때 오류 발생

분류에서Dev

Flutter : 단일 목록 값을 표시 할 때 오류 발생

분류에서Dev

IIS에서 .net 핵심 웹 앱의 샘플 프로젝트를 게시 할 때 HTTP 오류 500.19 내부 서버 오류가 발생합니다.

분류에서Dev

Marketplace 앱을 게시 할 때 오류 발생

분류에서Dev

iTunes에 앱을 업로드 할 때 오류가 발생합니다.

분류에서Dev

새 활동을 시작할 때 오류 발생 Android

분류에서Dev

내 장치에서 내 앱을 시작하려고 할 때 xcode에서 시작 옵션 nil로 오류가 발생합니까?

분류에서Dev

document.getElementById를 사용하여 JavaScript 출력을 화면에 표시 할 때 오류가 발생했습니다.

분류에서Dev

내 웹 사이트에 게시 할 때 내부 서버 오류가 발생하지만 게시물을 삭제할 때 발생하지 않음

분류에서Dev

이메일을 보내려고 할 때 오류가 발생했습니다.

Related 관련 기사

  1. 1

    .dll을 다시 컴파일 할 때 발생하는 오류

  2. 2

    Android에서 Mandrill SMTP로 이메일을 보내려고 할 때 오류 발생

  3. 3

    다른 폴더에서 내 C ++ 프로그램을 컴파일 할 때 실행 파일에서 분할 오류가 발생합니다.

  4. 4

    URL이있는 파일을 내부 저장소 Android Studio로 다운로드 할 때 오류 발생

  5. 5

    내 저장소에 파일을 추가하려고 할 때 Git에서 readlink 오류가 발생합니다.

  6. 6

    내 웹 사이트에서 파일을 업로드 할 때이 오류가 발생합니다.

  7. 7

    데이터 배열을 JTable에 표시 할 때 오류 발생

  8. 8

    다른 Android 앱으로 파일을 전달할 때 발생하는 문제

  9. 9

    Google Play에서 내 앱을 테스트 할 때이 오류가 발생했습니다.

  10. 10

    내 Android 앱에 모듈을 추가 할 때 DuplicateFileException 발생

  11. 11

    내 프로젝트에 게시물을 업로드하려고 할 때 405 오류가 발생합니다.

  12. 12

    내 데이터베이스에서 게시물을 검색 할 때 오류가 발생했습니다.

  13. 13

    다른 함수 내에서 promise 함수를 호출 할 때 오류 발생

  14. 14

    한 앱을 다른 앱의 데이터베이스에 연결할 때 오류 발생

  15. 15

    zip 파일에서 파일을 추출 할 때 오류 발생

  16. 16

    Flutter에서 다운로드에 파일을 저장할 때 오류 발생

  17. 17

    내가 실행할 때마다 앱에서 Gmail 로그인 통합을 시도 할 때마다 동일한 오류가 표시됩니다.

  18. 18

    Python-파일에서 바이트 추출을 시도 할 때 오류 발생

  19. 19

    Linux 서버의 flask에서 파일을 다운로드 할 때 오류 발생

  20. 20

    시뮬레이터에서 Flutter 앱을 시작할 때 오류 발생

  21. 21

    Flutter : 단일 목록 값을 표시 할 때 오류 발생

  22. 22

    IIS에서 .net 핵심 웹 앱의 샘플 프로젝트를 게시 할 때 HTTP 오류 500.19 내부 서버 오류가 발생합니다.

  23. 23

    Marketplace 앱을 게시 할 때 오류 발생

  24. 24

    iTunes에 앱을 업로드 할 때 오류가 발생합니다.

  25. 25

    새 활동을 시작할 때 오류 발생 Android

  26. 26

    내 장치에서 내 앱을 시작하려고 할 때 xcode에서 시작 옵션 nil로 오류가 발생합니까?

  27. 27

    document.getElementById를 사용하여 JavaScript 출력을 화면에 표시 할 때 오류가 발생했습니다.

  28. 28

    내 웹 사이트에 게시 할 때 내부 서버 오류가 발생하지만 게시물을 삭제할 때 발생하지 않음

  29. 29

    이메일을 보내려고 할 때 오류가 발생했습니다.

뜨겁다태그

보관