点击事件类:
public voID onItemClick(AdapterVIEw<?> parent,VIEw v,int position,long ID){ LazyAdapter ca = (LazyAdapter)parent.getAdapter(); FolderList item_name = (FolderList)ca.getItem(position); FolderList documentID = (FolderList)ca.getItem(position); FolderList type = (FolderList)ca.getItem(position); 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... } else { Intent i = new Intent(getApplicationContext(),display_image.class); i.putExtra("item_name",item_name.folder_name); i.putExtra("ID",documentID.ID); i.putExtra("item_type",type.type); i.putExtra("User_ID",User_ID); i.getStringExtra("item_name"); ID = i.getStringExtra("ID"); i.getStringExtra("item_type"); startActivity(i); }}
我的代码:我想使用下载管理器
SoapPrimitive documentResponse = (SoapPrimitive)Envelope.getResponse(); Log.i("documentResponse",documentResponse.toString()); String DocAsstring = documentResponse.toString(); byte[] decodedString = Base64.decode(DocAsstring,Base64.DEFAulT); file direct = 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 request = new DownloadManager.Request(Uri.parse(name)); request.setDescription("Have Fun ;)"); request.setTitle("Downloading..."); // in order for this if to run,you must use the androID 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 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(Context.DOWNLOAD_SERVICE); manager.enqueue(request); ContentValues values= new ContentValues(); System.out.println(values); } catch (java.io.IOException e) { Log.e("PictureDemo","Exception in photoCallback",e); } }
请建议如何使用下载管理器?谢谢
解决方法 您可以使用Progressbar来完成此任务.首先,在您的界面中添加一个进度条,如下所示:
<Progressbar androID:ID="@+ID/progress_bar" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" />
然后在您的代码中更新您的方法,如下所示:
protected Progressbar mProgressbar;protected long downloadID;protected DownloadManager manager;public voID startdownload() { //<SET UP DOWNLOAD MANAGER HERE> downloadID = manager.enqueue(request); mProgressbar = findVIEwByID(R.ID.progress_bar); Timer myTimer = new Timer(); myTimer.schedule(new TimerTask() { @OverrIDe public voID 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.close(); int dl_progress = (bytesDownloaded * 1f / bytesTotal) * 100; runOnUiThread(new Runnable(){ @OverrIDe public voID run(){ mProgressbar.setProgress((int) dl_progress); } }); } },10);}总结
以上是内存溢出为你收集整理的如何在Android中显示进度条中的下载进度?全部内容,希望文章能够帮你解决如何在Android中显示进度条中的下载进度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)