(對不起我的英語)運行任務時,顯示通知
我需要用我的第一個程序,我必須作出週五通過對研究過程中幫助...
我想創建一個應用程序,該應用程序將顯示帶添加提醒的表格中的描述的通知。我在獲取下一個描述的機制方面遇到問題。顯示通知後,我對應用程序進行了描述。不幸的是,這在應用程序關閉時不起作用。
public void onReceive(Context context, Intent intent) {
ScheduleNotification.completeWakefulIntent(intent);
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
descToShow = d1;
DataBaseHandler dbh = new DataBaseHandler(context);
dbh.open();
dbh.DeleteRow(descToShow);
dbh.close();
Toast.makeText(context, descToShow, Toast.LENGTH_LONG).show();
//notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.icon);
builder.setContentTitle(descToShow);
builder.setContentText(descToShow); //--description event--
builder.setAutoCancel(false).build();
//from android dev:
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, builder.build());
PendingIntent notifyPIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
builder.setContentIntent(notifyPIntent);
}
任何想法?
我github上的所有代碼:https://github.com/azernax/dForget
不要爲每個值使用單獨的'SharedPreferences' - 可以容納所有值。相關值應存儲在一個文件中 – Markaos