0
如果我想在按下android模拟器上的按钮时弹出消息“Hello”,通知会弹出。我应该使用哪些代码?再次在Android模拟器上按下按钮时发出通知
如果我想在按下android模拟器上的按钮时弹出消息“Hello”,通知会弹出。我应该使用哪些代码?再次在Android模拟器上按下按钮时发出通知
谢谢,这是示例代码通知用户,当用户点击该按钮
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);
}
});
此代码可以帮助你
这应该有所帮助。谢谢 –
非常欢迎亲爱的.. –
很好的回答,我喜欢它。谢谢 –