【发布时间】:2017-07-20 04:24:42
【问题描述】:
我正在使用此代码为用户保持持续的通知,但我应该如何在点击后正确返回到应用程序?
Ps.:实际代码在OnFormClose和OnFormDestroy上包含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;
【问题讨论】:
-
这太完美了
-
@Victoria 如果您发布解决方案的相关部分,您可能会得到一个被接受的答案,而且即使论坛文章消失,答案仍然会在这里找到
-
@mjn,好点,但我仍然没有环境可以测试。我主要回答 FireDAC 问题,因为我可以阅读源代码,老实说,我不是这里的得分猎人。我很感激任何反馈,我回答的东西是有效的:)你可以自己添加答案;)——
标签: delphi android-intent android-pendingintent delphi-10.1-berlin