java - How can Add downloading status show (like as android defualt browser ) -


how can show downloading status bar similar android default browser:

you should search before post question here friend.

there component in android api called downloadmanager.


the android downloadmanager introduced in android 2.3. (api 9) system service allows handle long-running http downloads in background , notify triggering application via broadcast receiver once download finished.

here little example using downloadmanager. project called “de.vogella.android.downloadmanager” activity “downloadmanageractivity” based on android api9 or higher.

change “main.xml” following.

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="fill_parent"     android:layout_height="fill_parent">     <button android:text="start download" android:id="@+id/button1"         android:layout_width="wrap_content" android:layout_height="wrap_content"         android:onclick="onclick"></button>     <button android:text="view downloads" android:id="@+id/button2"         android:layout_width="wrap_content" android:layout_height="wrap_content"         android:onclick="showdownload"></button>     <imageview android:layout_height="wrap_content" android:id="@+id/imageview1"         android:src="@drawable/icon" android:layout_width="wrap_content"></imageview> </linearlayout> 

change code of activity following. package de.vogella.android.downloadmanager;

import android.app.activity; import android.app.downloadmanager; import android.app.downloadmanager.query; import android.app.downloadmanager.request; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.database.cursor; import android.net.uri; import android.os.bundle; import android.view.view; import android.widget.imageview;  public class downloadmanageractivity extends activity {     private long enqueue;     private downloadmanager dm;      /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          broadcastreceiver receiver = new broadcastreceiver() {             @override             public void onreceive(context context, intent intent) {                 string action = intent.getaction();                 if (downloadmanager.action_download_complete.equals(action)) {                     long downloadid = intent.getlongextra(                             downloadmanager.extra_download_id, 0);                     query query = new query();                     query.setfilterbyid(enqueue);                     cursor c = dm.query(query);                     if (c.movetofirst()) {                         int columnindex = c                                 .getcolumnindex(downloadmanager.column_status);                         if (downloadmanager.status_successful == c                                 .getint(columnindex)) {                              imageview view = (imageview) findviewbyid(r.id.imageview1);                             string uristring = c                                     .getstring(c                                             .getcolumnindex(downloadmanager.column_local_uri));                             view.setimageuri(uri.parse(uristring));                         }                     }                 }             }         };          registerreceiver(receiver, new intentfilter(                 downloadmanager.action_download_complete));     }      public void onclick(view view) {         dm = (downloadmanager) getsystemservice(download_service);         request request = new request(                 uri.parse("http://www.vogella.de/img/lars/larsvogelarticle7.png"));         enqueue = dm.enqueue(request);      }      public void showdownload(view view) {         intent = new intent();         i.setaction(downloadmanager.action_view_downloads);         startactivity(i);     } } 

also add permission go internet app.

if implemented example have android application can download picture (sorry ;-)) , allow switch download manager see finished downloads.

hope helps.

source: http://blog.vogella.com/2011/06/14/android-downloadmanager-example/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -