저는 여전히 Android에 익숙하지 않으며 내 알림 창의 진행률 표시 줄을 부드럽게 처리하고 페블에 대한 백만 건의 업데이트를 실행하지 않고 "올바른 방법"으로 개선하려고합니다. 이 코드는 내가 사용하고있을 때와 마찬가지로 알림이 그려지고 진행률 표시 줄이 예상대로 완료 될 때 "정상적으로 작동합니다.안드로이드 - 알림 진행률 표시 줄을 올바르게 업데이트 중입니다.
제 페블 시계가 내 앱 알림을 받도록 설정하면 문제가되었습니다. 이로 인해 업로드 속도가 얼마나 빠름에 따라 이미지가 업로드되는 횟수가 약 50 회 정도 진동합니다.
나는이 모든 것을 잘못하고 있다고 가정하며, 내가하려고하는 일을하는 훨씬 더 좋은 방법이있다.
내 통지의 진행 표시 줄은 다음 코드로 업데이트됩니다
private int upload_progress;
private Long time_previous_progress = Calendar.getInstance().getTimeInMillis();
protected void onProgressUpdate(Integer... progress) {
Long time_now = Calendar.getInstance().getTimeInMillis();
if(
((time_now - time_previous_progress) < 55) // 55ms minimum delay
|| (progress[0] < 0 && progress[0] > 100) // progress >0 && <100
|| progress[0].equals(upload_progress) // progress changed
|| ! App.getStatus() // watcher is running
)
{
return;
}
time_previous_progress = time_now;
upload_progress = progress[0];
int upload_counter = getUploadCounter();
int upload_total = db.getReadyImagesCount();
NotificationHandler.notify(context, upload_progress, upload_counter, (upload_total + upload_counter));
}
통지는 다음이 코드로 생성됩니다
이public static int notify(Context context, Integer progress, Integer upload_count, Integer upload_total)
{
Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
String notif_title = context.getResources().getString(R.string.instant_upload_title);
String notif_progress = context.getResources().getString(R.string.instant_upload_progress);
String notif_ticker = String.format(notif_progress, upload_count, upload_total);
String notif_msg = String.format(notif_progress, upload_count, upload_total);
Intent intent_swipe = new Intent(context, NotifyReceiver.class);
intent_swipe.setAction("notification_cancelled");
PendingIntent pendingIntent_swipe = PendingIntent.getBroadcast(context, 0, intent_swipe, PendingIntent.FLAG_CANCEL_CURRENT);
Intent intent_click = new Intent(context, Settings.class);
intent_click.putExtra("notification_clicked", true);
PendingIntent pendingIntent_click = PendingIntent.getActivity(context, 0, intent_click, PendingIntent.FLAG_CANCEL_CURRENT);
int pro_max = 100;
int pro_cur = 0;
if(progress < 100)
{
pro_cur = progress;
}else{
pro_cur = pro_max = 0;
}
//new NotificationCompat.Builder(context)
NotificationCompat.Builder builder = new NotificationCompat.Builder(context) //PixelRelayApplication.getNotificationBuilder()
.setTicker(notif_ticker)
.setContentTitle(notif_title)
.setContentText(notif_msg)
.setNumber(upload_count)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(bm)
.setContentIntent(pendingIntent_click)
.setDeleteIntent(pendingIntent_swipe)
.setAutoCancel(true)
.setOngoing(true)
.setWhen(Calendar.getInstance().getTimeInMillis())
.setProgress(pro_max, pro_cur, false);
Notification notification = builder.build();
// Put the auto cancel notification flag
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFY_ME_ID, notification);
return NOTIFY_ME_ID;
}
문제는 알림을 업데이트 할 때마다 빌더를 다시 만드는 것입니다. 같은 빌더를 사용해보십시오. 나는 그것이 도움이 될 것이라고 생각한다. –