Notificationベースアプリケーション
2248 ワード
package com.tf.android.test;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
/**
* @title:
* @description: HelloWorld
* @version 1.0
* @created on 2010-12-3 02:33:14
*/
public class NotificationActivity extends Activity
{
private static final int NOTICE_ID = 1222;
private Button notify;
private Button cancel;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
notify = (Button)findViewById(R.id.noti);
cancel = (Button)findViewById(R.id.cancel);
notify.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
notityMe();
}
});
cancel.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
final NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
manager.cancel(NOTICE_ID);
}
});
}
private void notityMe()
{
// ,
final NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// p1: p2: p3:
Notification notification = new Notification(R.drawable.icon, " ", System.currentTimeMillis());
// Intent,
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, NotificationActivity.class), 0);
//
notification.setLatestEventInfo(this, " title", " ", intent);
//
manager.notify(NOTICE_ID, notification);
}
}