samiasoft
دوشنبه 01 مرداد 1397, 23:54 عصر
سلام دوستان
برای دانلود فایل با دانلود منیجر چنین کلاسی رو بصورت زیر ایجاد کردم اما
مشکلی که داشتم این هستش که :
1- چگونه وقتی دانلود تمام شد نوتیفیکیشن دانلود رو پاک کنیم ؟
2- چگونه دانلود را کنسل کنیم هنگام خارج شدن از برنامه؟
public class Download_Manager {
private Context context;
DownloadManager manager;
DownloadManager.Request request;
public Download_Manager(Context context) {
this.context = context;
}
public void startDownload(String url) {
request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Some descrition");
request.setTitle("Some title");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager. Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
String filename=url.substring( url.lastIndexOf('/')+1, url.length() );
request.setDestinationInExternalPublicDir(Environm ent.DIRECTORY_DOWNLOADS, filename);
manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE) ;
context.registerReceiver(onComplete,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPL ETE));
manager.enqueue(request);
Toast.makeText(context, "آغاز دانلود در نوتیفیکیشن", Toast.LENGTH_SHORT).show();
}
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Toast.makeText(context, "دانلود کامل شد", Toast.LENGTH_SHORT).show();
}
};
}
برای دانلود فایل با دانلود منیجر چنین کلاسی رو بصورت زیر ایجاد کردم اما
مشکلی که داشتم این هستش که :
1- چگونه وقتی دانلود تمام شد نوتیفیکیشن دانلود رو پاک کنیم ؟
2- چگونه دانلود را کنسل کنیم هنگام خارج شدن از برنامه؟
public class Download_Manager {
private Context context;
DownloadManager manager;
DownloadManager.Request request;
public Download_Manager(Context context) {
this.context = context;
}
public void startDownload(String url) {
request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Some descrition");
request.setTitle("Some title");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager. Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
String filename=url.substring( url.lastIndexOf('/')+1, url.length() );
request.setDestinationInExternalPublicDir(Environm ent.DIRECTORY_DOWNLOADS, filename);
manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE) ;
context.registerReceiver(onComplete,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPL ETE));
manager.enqueue(request);
Toast.makeText(context, "آغاز دانلود در نوتیفیکیشن", Toast.LENGTH_SHORT).show();
}
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Toast.makeText(context, "دانلود کامل شد", Toast.LENGTH_SHORT).show();
}
};
}