私はハニカム用に開発しており、何日もこの問題を解決しようとしています。私は意図のない通知サービスを持っています (必要ありません)。問題は、displaymessage関数を呼び出すたびに毎回通知が表示されるため、100 個の通知を受け取ることです。一度だけポップアップし、その後はパーセントのテキストのみを変更したいと思います。マーケット プログレス バーとパーセンテージからのダウンロードに似ています。関数を分離し、新しいテスト コードを作成しましたが、成功しませんでした。これを別の角度から見ると、新しい通知を作成せずに、既存の通知のテキストを変更したいと考えています。手伝ってくれませんか?
これがコード全体です(分離後):
package com.disp;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.os.SystemClock;
public class DispalyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for (int i = 0; i < 100; i++) {
SystemClock.sleep(300);
displaymessage(""+i+"%");
}
}
public void displaymessage(String string) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(R.drawable.ic_launcher, "Notification Service", System.currentTimeMillis());
Context context = getApplicationContext();
notification.setLatestEventInfo(context, "Downloading Content:", string, null);
final int HELLO_ID = 2;
mNotificationManager.notify(HELLO_ID, notification);
}
}