J'utilise ce code pour garder une notification en cours pour l'utilisateur, mais comment dois-je procéder pour revenir correctement à l'application après avoir cliqué dessus ?
Ps. : le code actuel contient ntfManager.cancelAll;
en OnFormClose
y OnFormDestroy
pour éviter que l'application soit tuée et que l'icône reste.
procedure TForm1.FormSaveState(Sender: TObject);
var
ntfManager: JNotificationManager;
ntfBuilder: JNotificationCompat_Builder;
Ntf: JNotification;
contentIntent: JPendingIntent;
Intent: JIntent;
const
r_drawable_ic_btn_speak_now = 17301668;
begin
Form1.Tag := 1;
ntfBuilder:= TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context);
//ntfBuilder.setSmallIcon(TAndroidHelper.Context.getResources.getIdentifier(StringToJString('ic_test'), StringToJString('drawable'), TAndroidHelper.Context.getPackageName));
ntfBuilder.setSmallIcon(r_drawable_ic_btn_speak_now);
ntfBuilder.setContentTitle(StrToJCharSequence('Content Title'));
ntfBuilder.setContentText(StrToJCharSequence('Content Test'));
ntfBuilder.setAutoCancel(True);
ntfBuilder.setOngoing(True);
Intent := TJIntent.Create;
// What should I do with this intent for returning to the app?
contentIntent := TJPendingIntent.Create;
// How I add the Intent on this PendingIntent?
// Where I should add the FLAG_ACTIVITY_NEW_TASK flag?
ntfBuilder.setContentIntent(contentIntent);
Ntf:= ntfBuilder.build;
ntfManager:= TJNotificationManager.Wrap((TAndroidHelper.Context.getSystemService(TJContext.JavaClass.NOTIFICATION_SERVICE) as ILocalObject).GetObjectID);
ntfManager.notify(1, Ntf);
end;