2 votes

Comment revenir à l'application après avoir cliqué sur une notification ?

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;

-1voto

Lxh Points 1
AIntent :=TJIntent.Create;
AIntent.setClass(SharedActivityContext, SharedActivityContext.getClass);
PendingIntentClick := TJPendingIntent.JavaClass.getActivity(TAndroidHelper.Context,0,
       AIntent,
       TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT);

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X