현재 URL에서 mp3를 다운로드하면 상태 표시 줄 알림이 표시됩니다. 그것은 괜찮아 시작 (그리고 파일이 잘 다운로드), 그러나, 진행률 표시 줄이 진행되지 않습니다. 그것은 여전히 그대로 유지됩니다. 어디서 코드를 넣을 지 모르므로 다운로드 진행 상황을 알려줍니다. 어떤 아이디어?진행률 표시 줄이있는 Android- 상태 표시 줄 알림
감사합니다.
public class DownloadFile extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... url) {
try {
URL url2 = new URL(sdrUrl);
HttpURLConnection c = (HttpURLConnection) url2.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
int lengthOfFile = c.getContentLength();
String PATH = Environment.getExternalStorageDirectory()
+ "/download/";
Log.v("", "PATH: " + PATH);
File file = new File(PATH);
file.mkdirs();
String [] path = url2.getPath().split("/");
String mp3 = path [path.length-1];
String sdrMp3 = mp3.replace("%20", "");
File outputFile = new File(file, sdrMp3);
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
publishProgress((int)(len1*100/lengthOfFile));
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
}catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
}
public void DownloadNotification(){
Intent intent = new Intent(this, BlogActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
final Notification notification = new Notification(R.drawable.sdricontest, "Downloading...", System
.currentTimeMillis());
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout);
notification.contentIntent = pendingIntent;
notification.contentView.setImageViewResource(R.id.download_icon, R.drawable.sdricontest);
notification.contentView.setTextViewText(R.id.download_text, "simulation in progress");
notification.contentView.setProgressBar(R.id.download_progress, 100, progress, false);
getApplicationContext();
final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.notify(42, notification);
}
}
이것은 단지 ANR 내 애플 리케이션. 사용자가 단추를 누르면 asynctask 및 다운로드 알림을 실행하고 있습니다. – Splitusa
생성자와 onPostExecute를 추가했습니다. 이 코드는 작동하는 코드에서 파생 된 것입니다. – Suchi
그래서 상태 표시 줄 알림을 사용하지 않고 화면에 표시되는 진행 대화 상자 로딩 바를 ... – Splitusa