بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
دانلود فایل از سرور(کار نمی کند)
با این کلاس می خوام یه فایل mp3 از سرور دانلود کنم ولی نه پوشه توی حافظه ساخته می شه و نه فایل دانلود می شه لطفا کمک کنید؟!
private class MusicDownload extends AsyncTask<String,Integer,String>{
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(DetailNewsActivity.this);
progressDialog.setTitle("در حال دریافت آهنگ ...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(100);
progressDialog.setProgress(0);
progressDialog.show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String path = params[0];
int file_length = 0;
try {
URL url = new URL(path);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
file_length = urlConnection.getContentLength();
File new_folder = new File("/sdcard/musicAlbum");
if (!new_folder.exists()){
new_folder.mkdir();
}
File input_file = new File(
new_folder,"rstak.mp3");
InputStream inputStream = new BufferedInputStream(
url.openStream(),8192);
byte[] data = new byte[1024];
int total = 0;
int count = 0;
OutputStream outputStream = new FileOutputStream(input_file);
while ((count=inputStream.read(data))!=-1){
total+=count;
outputStream.write(data,0,count);
int progress = (int) (total*100)/file_length;
publishProgress(progress);
}
inputStream.close();
outputStream.close();
} catch (MalformedURLException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
}
return "دانلود کامل شد.";
}
@Override
protected void onProgressUpdate(Integer... values) {
progressDialog.setProgress(values[0]);
}
@Override
protected void onPostExecute(String result) {
progressDialog.hide();
Toast.makeText(getApplicationContext(),
result,Toast.LENGTH_SHORT).show();
String path = "sdcard/musicAlbum/download_music.mp3";
}
}
0
0
Oops حل شد گیری کردیم با این اندروید 6 اجازه دسترسی به نوشت روی کارت حافظه رو بهش نداده بودم داخل برنامه (9 سال پیش)
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .