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);
}
});
此代碼可以幫助你
這應該有所幫助。謝謝 –
非常歡迎親愛的.. –
很好的回答,我喜歡它。謝謝 –