Recent

Author Topic: AppNotificationManagerDemo1 crashes when running on android13 (solved)  (Read 1216 times)

iwizard

  • New member
  • *
  • Posts: 8
I compiled and ran AppNotificationManagerDemo1, unfortunately, my attempt failed under android13, the program crashed after clicking the Push System Notification button, but my phone using android4.1 also ran successfully, what is the reason, how do I need to troubleshoot and solve the problem?
« Last Edit: February 09, 2024, 04:22:50 am by iwizard »

marcos-ebm

  • New Member
  • *
  • Posts: 49
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #1 on: February 08, 2024, 06:57:09 am »
[using the translator]

From what I've noticed, it doesn't work on new phones because of the appcompat theme.

on old smartphones, it works with the default theme (deviceDefault)

I believe the NotificationManager component is not updated to use appCompat
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

marcos-ebm

  • New Member
  • *
  • Posts: 49
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #2 on: February 08, 2024, 08:10:59 am »
[using the translator]

The component is working perfectly, there is something in the Demo that is bad, but as it is a Demo, it is better not to use it

do it like this

Create a new project, add only the NotificationManager1 component to the form

create a button and place the code in the button's onClick

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.Button1Click(Sender: TObject);
  2. begin
  3.    NotificationManager1.Notify();
  4. end;

try it



It's better to use the Demos just to see the codes

As the Lamw project changed over time, the Demos didn't keep up, but over time everything got better.
« Last Edit: February 08, 2024, 08:13:33 am by marcos-ebm »
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

iwizard

  • New member
  • *
  • Posts: 8
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #3 on: February 08, 2024, 10:10:40 am »
Thanks for the reply, I created a new project, put a button and a jNotificationManager control on it, wrote the code in the click event of the button NotificationManager1.Notify(); No error is reported when the execution is executed, but the Notify message does not appear. :(

In addition, I found that the crash in the demo problem was not caused by jNotificationManager, but by jIntentManager, which was caused by jNotificationManager1.SetContentIntent(......) Comment out, demo does not report error under android13, but again, the notify notification message does not appear after the code is executed.

Insid3Code

  • New Member
  • *
  • Posts: 26
  • Code Immersion
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #4 on: February 08, 2024, 05:54:28 pm »
Hi,
It related to missing required flag for PendingIntent.

EXCEPTION MSG:
Quote
called with pending exception java.lang.IllegalArgumentException:
com.example.appnotificationmanagerdemo1: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable,
e.g. if it needs to be used with inline replies or bubbles.

GAIN NOTIFICATIONS PERMISSION:
1- manifest side:
Code: Pascal  [Select][+][-]
  1. <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

2- use runtime permission call to ask user.

See animated gif:
https://i.imgur.com/aDPkQOC.gif

iwizard

  • New member
  • *
  • Posts: 8
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #5 on: February 09, 2024, 04:08:24 am »
Thank you very much for your guidance, I now use AndroidStudio to open the project after modification, and use AndroidStudio to compile and install can pop up the notify prompt window! :)

iwizard

  • New member
  • *
  • Posts: 8
Re: AppNotificationManagerDemo1 crashes when running on android13
« Reply #6 on: February 09, 2024, 04:21:10 am »
In addition, I experimented with it, as long as I added <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> permission, the notify pop-up window was also correctly popped up when I compiled and ran it directly in Lazarus, and I didn't need to open AndroidStudio to adjust jNotificationManager.java code, thanks again to everyone for their help! ;)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2304
Re: AppNotificationManagerDemo1 crashes when running on android13 (solved)
« Reply #7 on: February 11, 2024, 02:27:52 am »

Fixed and Update!

Thanks to All!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018