我正在使用此應用程序。我想要做的是在點擊按鈕的通知欄中顯示我的活動圖標。我希望它永久停留在那裏,直到其他事件完成。目前我沒有抓住過這樣的代碼,但它給予了很多的錯誤,請告訴我一個簡單的方法來做到這一點:在通知欄中顯示應用程序圖標
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(icon.isChecked()) {
CharSequence text = getText(R.string.local_service_started);
// Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.ic_launcher, "Track Your Life", System.currentTimeMillis());
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(), 0);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);
// Send the notification.
mNM.notify(NOTIFICATION, notification);
}
}
});
添加打印屏幕要什麼實現 –
我只想讓我的應用圖標留在通知欄中。就像在線時的WhatsApp或Skype圖標一樣。 –
請完整,準確地解釋**,「很多錯誤」的含義。此外,您可能希望使用'Notification.Builder'或'NotificationCompat.Builder',而不是直接嘗試自己創建'Notification'。 – CommonsWare