[FMX] 注册一个由 Android 调用的Intent

这段代码是从 FMX.Notification.Android 中抽出来的,从中我们可以学习如何注册一个 Intent 分享数据。FMX 目前我也是在学习,所以有些东西我也不好乱解释,毕竟俺不是很熟,误人子弟还是不要了。大家自己看源码分析好了。

procedure TNotificationCenterAndroid.ScheduleNotification(const ANotification: TNotification);

  function CreateNotificationAlarmIntent(const AID: Integer): JPendingIntent;
  var
    Intent: JIntent;
    Alarm: JFMXNotificationAlarm;
  begin
    Alarm := TJFMXNotificationAlarm.Create;
    Intent := TJIntent.Create;
    Intent.setClass(SharedActivityContext, Alarm.getClass);
    Intent.setAction(TJFMXNotificationAlarm.JavaClass.ACTION_FMX_NOTIFICATION);
    SaveNotificationIntoIntent(Intent, ANotification, AID);
    Result := TJPendingIntent.JavaClass.getBroadcast(SharedActivityContext, AID, Intent,
      TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT);
  end;

var
  PendingIntent: JPendingIntent;
  ID: Integer;
begin
  if not ANotification.Name.IsEmpty and FExternalStore.Contains(ANotification.Name) then
    CancelNotification(ANotification.Name);

  ID := TGeneratorUniqueID.GenerateID;
  PendingIntent := CreateNotificationAlarmIntent(ID);
  FExternalStore.SaveNotification(ANotification, ID);
  SharedAlarmManager.&set(TJAlarmManager.JavaClass.RTC_WAKEUP,
    DateTimeLocalToUnixMSecGMT(ANotification.FireDate), PendingIntent);
end;

 

滚动至顶部