单击通知后如何返回应用程序?

时间:2017-07-20 04:24:42

标签: delphi android-intent android-pendingintent delphi-10.1-berlin

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

Ps:实际代码包含ntfManager.cancelAll;OnFormClose上的OnFormDestroy,以防止应用被杀,图标仍然存在。

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;

1 个答案:

答案 0 :(得分:-1)

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