2012-03-01 11 views
1

私はHoneycomb用に開発しており、この問題を解決しようとしています。 私は意志なしで通知サービスを持っています(問題はありません)、問題は、毎回ディスプレイメッセージの呼び出しが毎回通知の機能を果たしているので、100通の通知を得ることです。私は一度だけポップアップしたいと思っていますし、パーセントのテキストを変更するだけです。マーケットプログレスバーとパーセンテージからのダウンロードと同様です。私は機能を分離し、新しいテストコードを作成しましたが、成功しませんでした。これを他の角度から見ると、新しい通知を作成せずに既存の通知のテキストを変更したいと考えています。 私を助けてもらえますか?ここAndroid Honeycomb通知ポップアップが頻繁に発生する

は(単離後)全体コードである:

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); 

    } 
} 

答えて

1

各通知を一意の整数IDでNotificationManagerによって識別されるので、新しい値でsetLatestEventInfo()を呼び出すことによって通知を修正することができ、通知のいくつかのフィールド値を変更し、notify()を再度呼び出します。

オブジェクトメンバーフィールド(コンテキストと通知のタイトルとテキストを除く)を使用して、各プロパティを修正できます。 contentTitleとcontentTextに新しい値を設定してsetLatestEventInfo()を呼び出すことによって、通知を更新するときにテキストメッセージを常に修正する必要があります。通知を更新するには、notify()を呼び出します。 (カスタム通知のレイアウトを作成した場合はもちろん、その後、これらのタイトルとテキスト値を更新しても効果はありません。)

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

から

関連する問題