我想延迟通知构建到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