tôi sử dụng plugin tuyệt vời https://github.com/katzer/cordova-plugin-local-notifications này để triển khai thông báo cục bộ khi tải xuống tệp. tôi không tìm thấy cách hiển thị thanh tiến trình trong thông báo như trong một thông báo gốc http://javatechig.com/wp-content/uploads/2014/05/Displaying-Progress-Notification-in-Android-Example.png bạn có thể trợ giúp không?thanh tiến trình hiển thị trong thông báo địa phương cordova
5
A
Trả lời
0
Sử dụng Plugin cordova-file-Chuyển và làm cho những thay đổi sau:
Bạn có thể thay đổi các plugin theo cách này cho nền tảng Android.
Tạo lớp FileProgressBarTask
với mã dưới đây:
package org.apache.cordova.filetransfer;
import android.app.NotificationManager;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
class FileProgressBarTask extends AsyncTask<Void, Integer, Integer> {
private NotificationCompat.Builder mBuilder;
private NotificationManager mNotificationManager;
int id = 0;
int progress = 0;
FileProgressBarTask(NotificationCompat.Builder mBuilder, NotificationManager mNotificationManager, int id){
Log.d("TAG", "Progress Bar");
this.mBuilder = mBuilder;
this.mNotificationManager = mNotificationManager;
this.id = id;
super.execute();
}
@Override
protected void onPreExecute(){
super.onPreExecute();
mBuilder.setProgress(150, 0, false);
mNotificationManager.notify(id, mBuilder.build());
}
@Override
protected void onProgressUpdate(Integer... values){
mBuilder.setProgress(150, values[0], false);
mNotificationManager.notify(id, mBuilder.build());
super.onProgressUpdate(values);
}
@Override
protected Integer doInBackground(Void... params) {
return null;
}
@Override
protected void onPostExecute(Integer result){
super.onPostExecute(result);
mBuilder.setContentText("Download Concluído");
mBuilder.setProgress(0, 0, false);
mNotificationManager.notify(id, mBuilder.build());
}
}
Thay đổi lớp FileTransfer
với mã dưới đây:
import android.content.res.Resources;
import android.content.Context;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
Trên dòng ~ 700 trong phương pháp tải trên lớp FileTransfer
:
Context contextApplication = cordova.getActivity().getApplicationContext();
Resources resources = contextApplication.getResources();
String pkgName = contextApplication.getPackageName();
int resId = resources.getIdentifier("ic_action_download", "drawable", pkgName);
mNotificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(cordova.getActivity());
mBuilder.setContentTitle("Download File")
.setContentText("Progress")
.setSmallIcon(resId);
final FileProgressBarTask progressBarTask = new FileProgressBarTask(mBuilder, mNotificationManager, id);
Tìm mã khối trên phương thức d ownload có chứa: while
và progress.setLoaded(inputStream.getTotalRawBytesRead());
trên phương pháp download, chèn mã dưới đây:
long lng = Math.abs((progress.getLoaded()/100)/100);
progressBarTask.onProgressUpdate(Integer.parseInt(String.valueOf(lng)));
Dựa trên:
Các vấn đề liên quan
- 1. hiển thị thanh tiến trình trong hộp thoại cảnh báo
- 2. ActionBar không hiển thị thanh tiến trình
- 3. Chỉ hiển thị thanh tiến trình wget?
- 4. Hiển thị thông báo bánh mì nướng địa phương
- 5. Tạo thông báo địa phương để phản hồi thông báo đẩy (từ firebase) trong cordova/ionic
- 6. Cordova Phonegap thông báo địa phương không hoạt động
- 7. Schedule thông báo địa phương mỗi ngày với PhoneGap cordova
- 8. Hiển thị thanh tiến trình trong khi loại trực tiếp đang hiển thị chế độ xem
- 9. Làm thế nào để hiển thị tiến trình tải xuống trong một thông báo trong ứng dụng lai ion?
- 10. Hiển thị thanh tiến trình khi Hoạt động đang tải
- 11. Hiển thị chỉ báo tiến trình bên trong NSSearchField
- 12. Thông báo tìm kiếm tiến trình không hiển thị trong DownloadManager android
- 13. Tuyên bố thanh tiến trình khai báo
- 14. thông báo tiến trình trong ECMAScript Promise
- 15. Android Retrofit - onProgressUpdate để hiển thị thông báo tiến độ
- 16. Thanh tiến trình trong thanh thông báo khi tải lên hình ảnh?
- 17. Thanh tiến trình tải lên Dropzone.js không hiển thị
- 18. Thanh tiến trình hiển thị tại thời điểm xử lý
- 19. hiển thị thanh tiến trình khi đang sử dụng git
- 20. Android - hiển thị văn bản ở giữa thanh tiến trình
- 21. cách hiển thị thanh tiến trình trước khi phát video
- 22. Chọn âm thanh tùy chỉnh cho thông báo địa phương
- 23. Thông báo tiến trình luồng nền trong MVVM?
- 24. Django - hiển thị tiến trình hành động
- 25. Cách nhận nút thanh tác vụ Windows của ứng dụng để hiển thị tiến trình thanh tiến trình
- 26. Thông báo địa phương trong WatchOS 3
- 27. Nhận thông báo tiến bộ từ một tiến trình con
- 28. thông báo địa phương tại Foreground
- 29. Gửi thông báo địa phương trong Android
- 30. Thanh tiến trình Android DialogFragment
có bất kỳ câu trả lời? –
không may là không – ginfo1