【发布时间】:2011-10-01 21:46:26
【问题描述】:
我想启动通知。当我点击它时,它会打开一个应用程序的新窗口。 这是我的代码:
public class Noficitation extends Activity {
NotificationManager nm;
static final int uniqueID = 1394885;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent= new Intent (Intent.ACTION_MAIN);
intent.setClass(getApplicationContext(), SchoolBlichActivity.class);
PendingIntent pi=PendingIntent.getActivity(this, 0, intent, 0);
String body = " body";
String title = "title!";
Notification n =new Notification(R.drawable.table, body, System.currentTimeMillis());
n.setLatestEventInfo(this, title, body, pi);
n.defaults = Notification.DEFAULT_ALL;
n.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(uniqueID,n);
finish();
}
顺便说一句,如果我在 finish() 之前添加 nm.cancel(uniqueID),它会创建通知并立即将其删除...
感谢您的帮助:D
【问题讨论】:
标签: java android android-activity notifications android-intent