Bir web sayfasını ayrıştırmak ve bir progressdialog stilini yatay olarak görüntülemek ve bayt için byte değerini artırmak istiyorum. BöyleAndroid: AsyncTask, ProgressDialog artışını nasıl güncelleyebilir
6
A
cevap
20
deneyin şey
bir ProgressDialog oluşturun.
ProgressDialog mProgressDialog = new ProgressDialog(Your_Activity.this);
mProgressDialog.setMessage("Here you can set a message");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.show();
MyAsyncTask obj = new MyAsyncTask();
obj.execute("url");
Kişisel AsyncTask Sınıf.
private class MyAsyncTask extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... url) {
int count;
try {
URL url = new URL(url[0]);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int length = connection.getContentLength();
// downlod the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/file_name.txt");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
publishProgress((int)(total*100/length));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
@Override
public void onProgressUpdate(String... args){
mProgressDialog.setProgress(args[0]);
}
}
}
Sen AndroidManifest dosyasında bu izni en vermek zorunda.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+0
Bazı URL'de her zaman -1 elde edeceksiniz, sonra bu kodu kullanacaksınız HttpURLConnection connection = (HttpURLConnection) url.openConnection(); \t \t connection.setRequestMethod ("HEAD"); \t \t connection.connect(); \t \t int length = connection.getContentLength(); –
İlgili konular
- 1. Android: AsyncTask ProgressDialog, ActivityGroup'da açılmıyor
- 2. Android ProgressDialog ile AsyncTask - Boş nesne başvurusu
- 3. ProgressDialog içinde AsyncTask ilerlemesini göstermiyor
- 4. Android AppCompat ProgressDialog?
- 5. Android AsyncTask,
- 6. android asyncTask iletişim kutusu
- 7. Android AsyncTask, onPostExecute
- 8. Unity3d Android eklentisi AsyncTask
- 9. android autocomplete AsyncTask Gecikmesi
- 10. Android AsyncTask arayamıyor onPostExecute
- 11. AsyncTask
- 12. AsyncTask
- 13. Android ProgressDialog Yazı Tipi ve Boyutu
- 14. Bir ProgressDialog gösteriliyorsa yönelim değişikliği nasıl yapılır?
- 15. Android AsyncTask ile ExecutorService nasıl kullanılır?
- 16. ProgressDialog görünmüyor
- 17. Android: Fragmanı AsyncTask (Aktivite Yok)
- 18. Android. Ölümcül istisna: AsyncTask # 1
- 19. Android hizmeti, başlatılan aktivitenin kullanıcı arayüzünü nasıl güncelleyebilir?
- 20. Android'de ProgressDialog öğesini belirle
- 21. Değer pas ben bu şekilde AsyncTask excuting am android
- 22. null'u execute(); android 4.0 AsyncTask yöntemi
- 23. Malzeme Tasarımı progressdialog
- 24. onProgressUpdate() AsyncTask içinde çalışmaz
- 25. AsyncTask nasıl düzeltilir?
- 26. android.os.NetworkOnMainThreadException AsyncTask
- 27. Android Canlı video karelerini işlemek için asynctask
- 28. Android Thread.sleep() in AsyncTask freeze UI
- 29. Android AsyncTask - doInBackground() neden idam edilmiyor?
- 30. AsyncTask onPostExecute,
Evet bir exemple vardır lütfen http://goo.gl/eeiu5 – Matthieu
mümkün mü? – MimmoG
Bu örnekte şu bağlantıya bakın: https://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask – Uttam