Andorid通知例(二)
5760 ワード
1 public class LaunchNotificationActivity
2 extends Activity {
3 /** Called when the activity is first created. */
4 @Override
5 public void onCreate(Bundle savedInstanceState) {
6 super.onCreate(savedInstanceState);
7
8 LinearLayout layout = new LinearLayout(this);
9 layout.setOrientation(LinearLayout.VERTICAL);
10
11 TextView textView = new TextView(this);
12 textView.setText(" 。");
13
14 Button button = new Button(this);
15 button.setText(" ");
16 button.setOnClickListener(new OnClickListener() {
17 @Override
18 public void onClick(View v) {
19 NotificationManager mNotificationManager =
20 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
21 int icon = R.drawable.smalllogo;
22 long when = System.currentTimeMillis();
23 Notification notification = new Notification(icon, " ", when);// , ,
24 notification.defaults = Notification.DEFAULT_SOUND;//
25 // Intent openintent = new Intent(this, OtherActivity.class);
26 PendingIntent contentIntent =
27 PendingIntent.getActivity(LaunchNotificationActivity.this, 0, null, 0);// openintent
28 notification.setLatestEventInfo(LaunchNotificationActivity.this, " ",
29 " ~ XXX , ", contentIntent);
30 notification.contentIntent =
31 PendingIntent.getActivity(LaunchNotificationActivity.this, 0,
32 new Intent(LaunchNotificationActivity.this,
33 LaunchNotificationActivity.class), 0);
34 notification.flags |= Notification.FLAG_AUTO_CANCEL;//
35 notification.defaults |= Notification.DEFAULT_SOUND;
36 mNotificationManager.notify(0, notification);//
37 }
38 });
39
40 layout.addView(textView);
41 layout.addView(button);
42 this.setContentView(layout);
43 }
44 }