How to Show download progress in progress bar in Android? -


I am using Net Web Services and I am able to download the file to the SD card, but I can see the progress bar I want to show when a special file is downloaded and is complete and then I want to see the options such as viewing or canceling.

Click on event class:

  public void onItemClick (AdapterView & lt;? & Gt; parent, see v, int status, long id) {casual adapter ca = (LazyAdapter) parent.getAdapter (); Folder list item_name = (folder list) ca.getItem (status); Folder list document id = (folder list) ca.getItem (status); Folder list type = (folder list) ca.getItem (status); Intent mIntent = new intent (); MIntent.putExtra ("item_name", item_name.folder_name); MIntent.putExtra ("item_id", DocumentID.ID); MIntent.putExtra ("item_type", type.type); MIntent.getStringExtra ("ITEM_NAME"); String type = mIntent.getStringExtra ("item_type"); Log.i ("type", type); If // some code here .....} and {intent I = new intent (getApplicationContext (), Display_image.class); I.putExtra ("item_name", item_name.folder_name); I.putext ("id", DocumentID.ID); I.putext ("item_type", type.type); I.putExtra ("user_id", user_id); I.getStringExtra ("ITEM_NAME"); Id = i.getStringExtra ("id"); I.getStringExtra ("item_type"); StartActivity (i); }}}); }   

My code: I want to use the download manager

  Soppromiry Document Response = (Sopprimiv) Envelope; Tetresons (); Log.i ("DocumentResponse", DocumentResponse.toString ()); String DocAsString = DocumentResponse.toString (); Byte [] decoded string = base 64 decode (docstestring, base64.default); Direct file = new file (environment .getExternalStorageDirectory (+ + "/ MyFolder"); If (! Direct.exists ()) {direct.mkdir (); } File photo = new file (environment .getExternalStorageDirectory () + "/ MyFolder", name); If (photo.exists ()) {photo.delete (); } {Try DownloadManager.Request = New DownloadManager.Request (Uri.parse (name)); Request.setDescription ("Have Fun;)"); Request.setTitle ("Downloading ..."); // In order of this to run, if you (Build.VERSION.SDK_INT> = Build.VERSION_CODT.HONEYCOMB) should use Android 3.2 to compile your app. {Request.allowScanningByMediaScanner (); Request.setNotificationVisibility (DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } FileOutputStream fos = New FileOutputStream (photo.getPath ()); Fos.write (decodedString); Fos.close (); DownloadManager Manager = (DownloadManager) getSystemService (reference.DOWNLOAD_SERVICE); Manager.enqueue (request); Material values ​​= new material value (); Println (value); } Hold (java.io.IOException e) {Log.e ("Picture Dmo", "Exception in Photoklback", e); }}   

How to use Download Manager in ??? Thank you

You can use a progress to complete it.

  Android: Android: Android: Android: layout_width = "wrap-content" Android: layout_height = "wrap_content"  

First, one such progress bar on your interface: Style = "@ android: style / widget.progressbar.small" />

Then update your code in this way:

  Protected progress Berg mprogressbar; Protected long download id; Protected DownloadManager Manager; Public Zero Start Download () {// & lt; SET UP Download Manager & gt; Download id = manager.query (request); MProgressBar = findViewById (R.id.progress_bar); Timer myitimer = new timer (); MyTimer.schedule (New TimerTask) {@Override Public Zero Run () {DownloadManager.Query q = New DownloadManager.Query (); Q.setFilterById (downloadId); Cursor cursor = manager.query (q); Cursor.moveToFirst (); Int bytes_downloaded = cursor.getInt (cursor.getColumnIndex (DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); Int bytes_total = cursor.getInt (cursor.getColumnIndex (DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); Cursor.co.us (); Int dl_progress = (bytes_loaded * 100 / Bytes_total); RunOnTabrade (New Runnabal) {@ Override Public Wired Run () {mProgressbar.setProgress (dl_progress)}}}}}}}, 0, 10); }    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -