gpt4 book ai didi

delphi - 点击通知后如何返回应用程序?

转载 作者:行者123 更新时间:2023-12-02 11:03:05 28 4
gpt4 key购买 nike

我使用此代码为用户保留持续通知,但单击它后我应该如何正确返回应用程序?

Ps.:实际代码在OnFormCloseOnFormDestroy上包含ntfManager.cancelAll;,以防止应用程序被杀死而图标保留。

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;

最佳答案

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

关于delphi - 点击通知后如何返回应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45205147/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com