1

これはすべて、最初のアクティビティからタスクを完了した後に呼び出している通知クラスのコードです。

しかし、現在のアプリケーションで通知を受け取るという問題が発生しています。

通知をダイアログボックスとして表示したい。

"R.layout.main" 

[OK] ボタンのあるダイアログ ボックスが含まれています。

public class Notif extends Activity implements View.OnClickListener {

  private Button Button01;

  private NotificationManager mManager;

  private static final int APP_ID = 0; 

  @Override

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    this.Button01 = (Button) this.findViewById( R.id.Button1);

    this.Button01.setOnClickListener(this);



    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

  }

  @Override

  public void onClick(View v) {

    Intent intent = new Intent(this,Notif.class);
    Notification notification = new Notification(R.drawable.icon,

    "Notify", System.currentTimeMillis());

       notification.setLatestEventInfo(Notif.this,"App Name","Description of the                     notification",PendingIntent.getActivity(this.getBaseContext(), 0, intent,

PendingIntent.FLAG_CANCEL_CURRENT));

    mManager.notify(APP_ID, notification);

  }

}
4

1 に答える 1

2

1) View.OnClickListener の実装でボタン リスナーを処理するのはなぜですか?

私がこれまでに見た標準的な方法は次のとおりです。

    Button01.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Your code
        }
    });

2) 通知は、画面上部の Android ステータス パネルを通じてユーザーに通知する方法です。通知とダイアログ ボックスで何をしたいのかわかりません。どちらにするか決めてください。

http://developer.android.com/guide/topics/ui/dialogs.html

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

通知を使用したい場合は、これが私のonStop()メソッドにあるものです (基本的には、Android ガイドに従うことで得られるものです)。

        Notification notification = new Notification(R.drawable.icon, "App Name", System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        Intent notificationIntent = new Intent(this, ClassToStart.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(getApplicationContext(), "App Name", "Press here to resume", contentIntent);
        mNotificationManager.notify(1, notification);

これはmNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);すでに行われていますonCreate()

本当に何をしようとしているのかわからない。

于 2011-03-17T11:17:52.097 に答える