1
當應用程序啓動時,它從數據庫中檢索數據。如果有新數據,我希望應用程序顯示應用內通知(橫幅)以警告用戶。應用內通知
目前我實現了這個:
if (!taskToNotify.isEmpty()) {
//Notification builder
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.ic_event_notification);
builder.setContentTitle(taskToNotify.get(0).getName() + mContext.getString(R.string.notification_content_task));
builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
// inbox style
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.addLine(mContext.getString(R.string.notification_detail_date) + taskToNotify.get(0).dueDateToString());
inboxStyle.addLine(mContext.getString(R.string.notification_detail_location) + taskToNotify.get(0).getLocationName());
// Moves the expanded layout object into the notification object.
builder.setStyle(inboxStyle);
mAdapter.notifyDataSetChanged();
builder.build();
}
但這並不暫時工作。代碼運行時不顯示通知。
有沒有可能在Android手機上做到這一點?或者我應該以另一種方式向用戶顯示這些信息?
謝謝您的寶貴幫助:)