0

DownloadManager를 사용하여 인터넷에서 이미지를 다운로드하고 갤러리 앱에 표시하려고합니다. 이미지를 기본 '다운로드'디렉토리에 저장합니다. 다운로드는 정상적으로 작동하며 성공을 통보받습니다. 갤러리 앱이 열리지 만 이미지는 표시되지 않습니다. 무엇이 문제 일 수 있습니까?DownloadManager로 다운로드 한 Android보기 이미지

      Cursor cursor = ((DownloadManager) getSystemService(DOWNLOAD_SERVICE)).query(ImageDownloadQuery); 
          if (cursor.moveToFirst()) { 
           String path = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); 
           File file = new File(URI.create(path)); 
           Uri uri = FileProvider.getUriForFile(ConversationDetailsActivity.this, 
             BuildConfig.APPLICATION_ID + ".fileprovider", 
             file); 
           Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri); 
           viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
           viewIntent.setType(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE))); 
           if (getPackageManager().resolveActivity(viewIntent, 0) != null) { // checking if there is an app installed that can handle this type of files 
            startActivity(viewIntent); 
           } else { // app that can view this file type is not found 
            Toast.makeText(getBaseContext(), "Please install an application to view this type of files", Toast.LENGTH_SHORT).show(); 
           } 
          } 

FileProvider 경로 :

<paths> 
    <cache-path 
     name="cache" 
     path="" 
     /> 
    <external-path 
     name="download" 
     path="Download/" 
     /> 
</paths> 

그리고 매니페스트 :

<provider 
    android:name="android.support.v4.content.FileProvider" 
    android:authorities="${applicationId}.fileprovider" 
    android:exported="false" 
    android:grantUriPermissions="true" 
    > 
    <meta-data 
     android:name="android.support.FILE_PROVIDER_PATHS" 
     android:resource="@xml/provider_paths" 
     /> 
</provider> 

여기 궁금해하는 사람들을위한 수정의

여기 내 코드입니다. 항상 의도 데이터 및 유형을 설정해야합니다. 하나를 설정하면 다른 설정이 지워집니다.

      DownloadManager.Query ImageDownloadQuery = new DownloadManager.Query(); 
          ImageDownloadQuery.setFilterById(referenceId); 
          Cursor cursor = ((DownloadManager) getSystemService(DOWNLOAD_SERVICE)).query(ImageDownloadQuery); 
          if (cursor.moveToFirst()) { 
           String path = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); 
           File file = new File(URI.create(path)); 
           Uri uri = FileProvider.getUriForFile(ConversationDetailsActivity.this, 
             BuildConfig.APPLICATION_ID + ".fileprovider", 
             file); 
           Intent viewIntent = new Intent(Intent.ACTION_VIEW); 
           viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
           viewIntent.setDataAndType(uri, cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE))); 
           if (getPackageManager().resolveActivity(viewIntent, 0) != null) { // checking if there is an app installed that can handle this type of files 
            startActivity(viewIntent); 
           } else { // app that can view this file type is not found 
            Toast.makeText(getBaseContext(), "Please install an application to view this type of files", Toast.LENGTH_SHORT).show(); 
           } 
          } 

답변

0

. 나쁘다. 데이터를 설정하지 않고 의도 유형을 설정하여 Uri을 삭제했습니다. 답변에 대한 원래 질문을 확인하십시오.