ToddFrankson 1 Posted November 9 I need some help in figuring out services.... I will be writing an app that needs to stay running, and every certain interval of time (at least 15 minutes or more-user configurable), open a file(in the apps folder) read it and then close the file(there's more to it but that is basics). I believe a foreground service is best, with it sticky, and start on boot.... I have those pieces. So the questions I have are the following: Like a weather app, I'd like it to stay in the Notification Panel at the top. How does that work? anyone have sample code? See the image.....How do I make my App stay like that in the notification panel, and then when the panel is "closed" it displays the current temperature. Has anyone done that in Delphi? I also will have the interface allowing to see the contents of the file the service opens, I believe I have some samples for that, but if it helps it will be a few configuration text items, and the UI will also open the same file, blocking the Service from doing so when the UI is launched. I believe I have that covered as well.... Share this post Link to post
Dave Nottage 554 Posted November 10 (edited) On 11/10/2024 at 5:16 AM, ToddFrankson said: How do I make my App stay like that in the notification panel You'd need to create the notification using the underlying classes, since the notification implementation in Delphi is yet to support "sticky" notifications. You could use the code in the TNotificationCenterAndroid.CreateNativeNotification method in rtl\common\System.Android.Notification.pas as a guide, and use the setOngoing method to make it "sticky". It's not exactly clear from your post what else you need solved. Edited November 10 by Dave Nottage 1 Share this post Link to post
ToddFrankson 1 Posted Tuesday at 12:16 AM On 11/10/2024 at 2:26 PM, Dave Nottage said: You'd need to create the notification using the underlying classes, since the notification implementation in Delphi is yet to support "sticky" notifications. You could use the code in the TNotificationCenterAndroid.CreateNativeNotification method in rtl\common\System.Android.Notification.pas as a guide, and use the setOngoing method to make it "sticky". It's not exactly clear from your post what else you need solved. Not necessarily solved. Just trying to understand the process.......... I've read that foreground services have some specific permissions that need to be requested, along with specific reasons why. I think I have a grasp on that now... As for the notifications, I can get that working by modifying your Kastri Demo Actually.....I used the JNotification_Builder and JNotificationManager to create the first Notification. For updates, I used the JNotificationCompat_Builder Still having issues getting the App Icon Using the following: var MainAppContext: JContext; AppIcon: Integer; Begin // Get the main application context by package name MainAppContext := TAndroidHelper.Context.getApplicationContext; // Fetch the application icon from the main application context AppIcon := MainAppContext.getPackageManager.getApplicationInfo( MainAppContext.getPackageName, 0).icon; ...... //other code related to building either the Notification_Builder or JNotificationCompat_Builder. .... End; The Icon is always a white box. Share this post Link to post
Dave Nottage 554 Posted Tuesday at 06:06 PM 16 minutes ago, ToddFrankson said: Still having issues getting the App Icon Using the following: As I mentioned in my first reply, you could use the code from TNotificationCenterAndroid.CreateNativeNotification as an example. Inside that is this: function GetDefaultIconID: Integer; begin Result := TAndroidHelper.GetResourceID('drawable/ic_notification'); if Result = 0 then Result := TAndroidHelper.Context.getApplicationInfo.icon; end; Share this post Link to post