我想延遲通知構建到1分鐘,我該怎麼做?我試圖插入一個處理程序和postDelaying它,但我得到了多個錯誤。延遲通知構建(Android)
public void customizedOnClick (View view){
String ticker = textTicker.getText().toString();
String title = textTitle.getText().toString();
String body = textBody.getText().toString();
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setTicker(ticker);
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle(title);
notification.setContentText(body);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
//Builds notification and issues it
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueID, notification.build());
}
你得到了什麼樣的錯誤? – Blackbelt
這是當我試圖使用處理程序,但我從原始代碼中刪除它。 錯誤:(59,33)錯誤:Handler是抽象的;無法實例化 錯誤:(60,16)錯誤:找不到符號方法postDelayed(,int) –
Oyee
您確定導入了正確的'Handler'。 java.util.logging包中有一個抽象處理程序。你想要一個'android.os' – Knossos