2017-02-09 13 views
0

html "<img src=\"data:image/jpeg;base64,someBase64String" />"。通常の画像URLと同じように(ユーザーの意見として)読み込みます。通常の画像URLの場合、私はDownloadManagerを使用します:DownloadManagerを使用してbase64イメージをダウンロードする方法は?私は次の私のカスタムブラウザからロードイメージが必要 :どのようにたとえばDownloadManager(私は画像のダウンロード(バイトにBASE64を変換し、ファイルに保存)した後、アプリケーションのダウンロードに表示するなければならないことを意味する)</p> <p>を使用してbase64で画像をダウンロードするには

DownloadManager.Request request = new DownloadManager.Request(source); 
     request.allowScanningByMediaScanner(); 
     request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
     request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); 
     request.setTitle(fileName); 
     request.setDescription(fileName); 
     DownloadManager dm = (DownloadManager) App.getInstance().getSystemService(Context.DOWNLOAD_SERVICE); 
     dm.enqueue(request); 

答えて

0
DownloadManager dm = (DownloadManager) App.getInstance().getSystemService(Context.DOWNLOAD_SERVICE); 
     String[] fileNameAndExt = getFileNameAndExt(file.getName()); 
     dm.addCompletedDownload(fileNameAndExt[0], file.getName(), true, "image/" + fileNameAndExt[1], file.getPath(), file.length(), true); 

また、マニフェストに許可が必要です:

<uses-permission android:name="android.permission.INTERNET" /> 

それは奇妙であるが、他の側、それは働いていません。

1

画像をダウンロードしてみてください。 uRlは画像URLです。

public void downloadFile(String uRl) { 
     File direct = new File(Environment.getExternalStorageDirectory() 
       + "/MyBox"); 

     if (!direct.exists()) { 
      direct.mkdirs(); 
     } 

     DownloadManager mgr = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE); 

     Uri downloadUri = Uri.parse(uRl); 
     DownloadManager.Request request = new DownloadManager.Request(
       downloadUri); 

     request.setAllowedNetworkTypes(
       DownloadManager.Request.NETWORK_WIFI 
         | DownloadManager.Request.NETWORK_MOBILE) 
       .setAllowedOverRoaming(false).setTitle("Demo") 
       .setDescription("Something useful. No, really.") 
       .setDestinationInExternalPublicDir("/MyFiles", "fileName.jpg"); 

     mgr.enqueue(request); 

    } 
+0

ソースコードでこのクラス(要求)が例外をスローする場合は、例外をスローします。 – mlevytskiy

+0

http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/4.4_r1-robolectric -0/android/app/DownloadManager.java#DownloadManager.Request – mlevytskiy

+0

if(scheme == null ||(!scheme.equals( "http")&&!scheme.equals( "https"))) – mlevytskiy

関連する問題