{"id":30399,"date":"2023-01-14T19:38:10","date_gmt":"2023-01-14T14:08:10","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/"},"modified":"2023-01-14T19:38:10","modified_gmt":"2023-01-14T14:08:10","slug":"solved-android-use-progressbar-for-the-audio-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/","title":{"rendered":"[Solved] Android use progressBar for the Audio [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-21249508\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"21249508\" data-parentid=\"21249286\" data-score=\"1\" data-position-on-page=\"2\" data-highest-scored=\"0\" data-question-has-accepted-highest-score=\"0\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Hi please try the below reference link for Progressbar tutorials.Hope it should helpful for you. You can download the sample source code and try it in your application.<\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.mkyong.com\/android\/android-progress-bar-example\/\">Progress Bar<\/a><\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/examples.javacodegeeks.com\/android\/core\/ui\/progressdialog\/android-progressdialog-example\/\">Progress bar for downloading a file<\/a><\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.compiletimeerror.com\/2013\/09\/android-progress-bar-example.html#.Ut3-kXO6Y8p\">Android Progress Bar Example<\/a><\/p>\n<p>Hi here i added the sample download file from server code. Please check and let me know.<\/p>\n<pre><code>    import java.io.InputStream;\n    import java.net.URL;\n    import android.app.Activity;\n    import android.app.ProgressDialog;\n    import android.os.Bundle;\n    import android.util.Log;\n    import android.view.View;\n    import android.widget.Button;\n    import java.io.BufferedInputStream;\n    import java.io.FileOutputStream;\n    import java.io.OutputStream;\n    import java.net.URLConnection; \n    import android.app.Dialog;\n    import android.graphics.drawable.Drawable;\n    import android.os.AsyncTask;\n    import android.os.Environment;\n    import android.widget.ImageView;\n\n    public class download extends Activity {\n\n        \/\/ button to show progress dialog\n        Button btnShowProgress;\n\n        \/\/ Progress Dialog\n        private ProgressDialog pDialog;\n        ImageView my_image;\n        \/\/ Progress dialog type (0 - for Horizontal progress bar)\n        public static final int progress_bar_type = 0; \n\n        \/\/ File url to download\n        private static String file_url = \"http:\/\/alshbab90.softsmedia.com\/helmi_1.mp3\";\n\n        @Override\n        public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.main);\n\n        \/\/ show progress bar button\n        btnShowProgress = (Button) findViewById(R.id.btnProgressBar);\n        \/\/ Image view to show image after downloading\n        my_image = (ImageView) findViewById(R.id.my_image);\n        \/**\n         * Show Progress bar click event\n         * *\/\n          btnShowProgress.setOnClickListener(new View.OnClickListener()   { \n\n            @Override\n            public void onClick(View v) {\n            \/\/ starting new Async Task\n            new DownloadFileFromURL().execute(file_url);\n            }\n        });\n        }\n\n        \/**\n         * Showing Dialog\n         * *\/\n        @Override\n        protected Dialog onCreateDialog(int id) {\n        switch (id) {\n        case progress_bar_type: \/\/ we set this to 0\n            pDialog = new ProgressDialog(this);\n            pDialog.setMessage(\"Downloading file. Please wait...\");\n            pDialog.setIndeterminate(false);\n            pDialog.setMax(100);\n            pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);\n            pDialog.setCancelable(true);\n            pDialog.show();\n            return pDialog;\n        default:\n            return null;\n        }\n        }\n\n        \/**\n         * Background Async Task to download file\n         * *\/\n        class DownloadFileFromURL extends AsyncTask&lt;String, String, String&gt; {\n\n        \/**\n         * Before starting background thread\n         * Show Progress Bar Dialog\n         * *\/\n        @Override\n        protected void onPreExecute() {\n            super.onPreExecute();\n            showDialog(progress_bar_type);\n        }\n\n        \/**\n         * Downloading file in background thread\n         * *\/\n        @Override\n        protected String doInBackground(String... f_url) {\n            int count;\n            try {\n            URL url = new URL(f_url[0]);\n            URLConnection conection = url.openConnection();\n            conection.connect();\n            \/\/ this will be useful so that you can show a tipical 0-100% progress bar\n            int lenghtOfFile = conection.getContentLength();\n\n            \/\/ download the file\n            InputStream input = new BufferedInputStream(url.openStream(), 8192);\n\n            \/\/ Output stream\n            OutputStream output = new FileOutputStream(\"\/sdcard\/helmi_1.mp3\");\n\n            byte data[] = new byte[1024];\n\n            long total = 0;\n\n            while ((count = input.read(data)) != -1) {\n                total += count;\n                \/\/ publishing the progress....\n                \/\/ After this onProgressUpdate will be called\n                publishProgress(\"\"+(int)((total*100)\/lenghtOfFile));\n\n                \/\/ writing data to file\n                output.write(data, 0, count);\n            }\n\n            \/\/ flushing output\n            output.flush();\n\n            \/\/ closing streams\n            output.close();\n            input.close();\n\n            } catch (Exception e) {\n            Log.e(\"Error: \", e.getMessage());\n            }\n\n            return null;\n        }\n\n        \/**\n         * Updating progress bar\n         * *\/\n        protected void onProgressUpdate(String... progress) {\n            \/\/ setting progress percentage\n            pDialog.setProgress(Integer.parseInt(progress[0]));\n           }\n\n        \/**\n         * After completing background task\n         * Dismiss the progress dialog\n         * **\/\n        @Override\n        protected void onPostExecute(String file_url) {\n            \/\/ dismiss the dialog after the file was downloaded\n             dismissDialog(progress_bar_type);\n\n             \/\/ Displaying downloaded image into image view\n             \/\/ Reading image path from sdcard\n               String imagePath =  Environment.getExternalStorageDirectory().toString() + \"\/helmi_1.mp3\";\n             \/\/ setting downloaded into image view\n            my_image.setImageDrawable(Drawable.createFromPath(imagePath));\n        }\n\n        }\n    }\n<\/code><\/pre>\n<p>Create <strong>main.xml:<\/strong><\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\nandroid:layout_width=\"fill_parent\"\nandroid:layout_height=\"fill_parent\"\nandroid:orientation=\"vertical\" &gt;\n\n&lt;!-- Download Button --&gt;\n&lt;Button android:id=\"@+id\/btnProgressBar\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:text=\"Download File with Progress Bar\"\n    android:layout_marginTop=\"50dip\"\/&gt;\n\n&lt;!-- Image view to show image after downloading --&gt;\n&lt;ImageView android:id=\"@+id\/my_image\"\n    android:layout_width=\"fill_parent\"\n    android:layout_height=\"wrap_content\"\/&gt;\n\n&lt;\/LinearLayout&gt;\n<\/code><\/pre>\n<p>Need to add AndroidManifest.xml permission as,<\/p>\n<pre><code>&lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\n&lt;uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" \/&gt;\n<\/code><\/pre>\n<p>Hope it should helpful for you. Please try and let me know. Thanks<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Android use progressBar for the Audio [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Hi please try the below reference link for Progressbar tutorials.Hope it should helpful for you. You can download the sample source code and try it in your application. Progress Bar Progress bar for downloading a file Android Progress Bar Example Hi here i added the sample download file from server code. Please check and &#8230; <a title=\"[Solved] Android use progressBar for the Audio [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\" aria-label=\"More on [Solved] Android use progressBar for the Audio [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[452,1742,1613,1623],"class_list":["post-30399","post","type-post","status-publish","format-standard","hentry","category-solved","tag-android","tag-android-progressbar","tag-audio","tag-progress-bar"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Android use progressBar for the Audio [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Android use progressBar for the Audio [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Hi please try the below reference link for Progressbar tutorials.Hope it should helpful for you. You can download the sample source code and try it in your application. Progress Bar Progress bar for downloading a file Android Progress Bar Example Hi here i added the sample download file from server code. Please check and ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-14T14:08:10+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Android use progressBar for the Audio [closed]\",\"datePublished\":\"2023-01-14T14:08:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\"},\"wordCount\":99,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"android\",\"android-progressbar\",\"audio\",\"progress-bar\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\",\"name\":\"[Solved] Android use progressBar for the Audio [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-01-14T14:08:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Android use progressBar for the Audio [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Android use progressBar for the Audio [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Android use progressBar for the Audio [closed] - JassWeb","og_description":"[ad_1] Hi please try the below reference link for Progressbar tutorials.Hope it should helpful for you. You can download the sample source code and try it in your application. Progress Bar Progress bar for downloading a file Android Progress Bar Example Hi here i added the sample download file from server code. Please check and ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/","og_site_name":"JassWeb","article_published_time":"2023-01-14T14:08:10+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Android use progressBar for the Audio [closed]","datePublished":"2023-01-14T14:08:10+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/"},"wordCount":99,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["android","android-progressbar","audio","progress-bar"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/","name":"[Solved] Android use progressBar for the Audio [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-14T14:08:10+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-android-use-progressbar-for-the-audio-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Android use progressBar for the Audio [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=30399"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30399\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=30399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=30399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=30399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}