【发布时间】:2011-09-16 09:59:53
【问题描述】:
如果我想让通知在我按下 android 模拟器上的 a 按钮时弹出一条消息“你好”。我应该使用什么代码?再次感谢
【问题讨论】:
-
好答案,我喜欢。谢谢
如果我想让通知在我按下 android 模拟器上的 a 按钮时弹出一条消息“你好”。我应该使用什么代码?再次感谢
【问题讨论】:
这是用户点击按钮时通知用户的示例代码
Button button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnclickListener(){
@Override
public void onClick(View v){
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.image,"Notification",System.currentTimeMillis());
Intent notificationIntent = new Intent(Currentclass.this,TargetActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), "Title", "Sub Title",contentIntent);
notification.flags=Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(143, notification);
}
});
此代码可能对您有所帮助
【讨论】: