~igor-cali/bilancio/stable

« back to all changes in this revision

Viewing changes to android/API33/main/java/com/igisw/openmoneybox/MainActivity.java

  • Committer: Igor Calì
  • Date: 2024-03-08 07:29:22 UTC
  • Revision ID: igor.cali0@gmail.com-20240308072922-d2upvp2sm83d5ygh
[v3.4.2.9] [Android] Fix GitLab #35 - Crash on Alarm Notification on Android S and higher.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Name:      
3
3
 * Purpose:   Core Code for OpenMoneyBox Application
4
4
 * Author:    Igor Calì (igor.cali0@gmail.com)
5
 
 * Created:   2024-01-05
 
5
 * Created:   2024-02-28
6
6
 * Copyright: Igor Calì (igor.cali0@gmail.com)
7
7
 * License:             GNU
8
8
 **************************************************************/
1668
1668
                        case Build.VERSION_CODES.R:
1669
1669
                        case Build.VERSION_CODES.S:
1670
1670
                        case Build.VERSION_CODES.S_V2:
1671
 
                                mBuilder.setColor(0x803f00);
 
1671
                        case Build.VERSION_CODES.TIRAMISU:
 
1672
                        case Build.VERSION_CODES.UPSIDE_DOWN_CAKE:
 
1673
                                int Clr;
 
1674
                                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
 
1675
                                        Clr = getResources().getColor(R.color.green_dark, this.getTheme());
 
1676
                                else Clr = 0x803f00;
 
1677
                                mBuilder.setColor(/*0x803f00*/Clr);
1672
1678
                                mBuilder.setSmallIcon(R.drawable.ic_launcher_brown);
1673
1679
                                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
1674
1680
                                        mBuilder.setChannelId(alarmId);
1693
1699
                stackBuilder.addParentStack(MainActivity.class);
1694
1700
                // Adds the Intent that starts the Activity to the top of the stack
1695
1701
                stackBuilder.addNextIntent(resultIntent);
 
1702
                int flags;
 
1703
                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
 
1704
                        flags = PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE;
 
1705
                else
 
1706
                        flags = PendingIntent.FLAG_UPDATE_CURRENT;
1696
1707
                PendingIntent resultPendingIntent =
1697
1708
                        stackBuilder.getPendingIntent(
1698
1709
                            0,
1699
 
                            PendingIntent.FLAG_UPDATE_CURRENT
 
1710
                            /*PendingIntent.FLAG_UPDATE_CURRENT*/flags
1700
1711
                        );
1701
1712
                mBuilder.setContentIntent(resultPendingIntent);
1702
1713
 
2280
2291
 
2281
2292
        @RequiresApi(Build.VERSION_CODES.O)
2282
2293
        private void ServiceNotification(){
 
2294
                int Clr;
 
2295
                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
 
2296
                        Clr = getResources().getColor(R.color.green_dark, this.getTheme());
 
2297
                else Clr = 0x803f00;
2283
2298
                Notification notification = new Notification.Builder(this, dummyId)
2284
2299
                                .setContentTitle(getResources().getString(R.string.notification_channel_service))
2285
2300
                                .setContentText(getResources().getString(R.string.notification_channel_service))
2286
 
                                .setColor(0x803f00)
 
2301
                                .setColor(/*0x803f00*/Clr)
2287
2302
                                .setSmallIcon(R.drawable.ic_launcher_brown)
2288
2303
                                .setChannelId(dummyId)
2289
2304
                                .build();