我最近開發了一個應用程序,但是,Android studio不再支持setLatestEventInfo
方法,因此,我試圖將此方法更改爲Notification.Builder
方法。但是,我很掙扎,因此我希望有人能夠支持我將這種方法改爲Notification.Builder
方法。無法解析setLatestEventInfo方法
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Fall Detector";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
mContext = getApplicationContext();
CharSequence contentTitle = "Fall Detector";
CharSequence contentText = "Running";
Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(mContext, contentTitle, contentText,
contentIntent);
mNotificationManager.notify(1, notification);
我試過了下面,但是,它說它不能解析符號contentintent。
String ns = Context.NOTIFICATION_SERVICE;
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Fall Detector";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
mNotificationManager = (NotificationManager) getSystemService(ns);
Notification.Builder builder = new Notification.Builder(mContext)
.setContentTitle("Fall Detector")
.setContentText("Running")
.setContentIntent(contentIntent);
builder.build();
Notification notification = builder.getNotification();
mNotificationManager.notify(1, notification);
「我正在努力」 - 請編輯您的問題,並顯示您已經嘗試了什麼以及您遇到了哪些具體問題。關於這個主題有幾十個現有的問題,比如[this](https://stackoverflow.com/q/32345768/115145)。如果你不希望人們將你的問題標記爲重複,你需要詳細解釋**,**是什麼使你的問題與現有問題不同。 – CommonsWare
更新的問題 –
我修改了代碼,但是,仍然得到說明無法解析符號內容的相同消息。 –