Sample to display (head-up) notifications on Android

I want to send a notification

I want to send a notification → There are many ways → It seems stable to use NotificationCompat.Builder

First of all, the notification is not displayed → Set the icon → Notification Channel required (Android O or later only)

I want to issue a head-up notification → Not → Raise priority → Allow vibration → Various others → Notification Channel needs to be set → The settings remain until you uninstall

** It's hard because the required information is too different for each API Level **

   private void notice()
    {
        final String CHANNEL_ID = "sample_notification_channel";
        final int ID = 0;
        NotificationCompat.Builder mBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID,"This is notificationChannel1",NotificationManager.IMPORTANCE_HIGH);
            channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            channel.enableVibration(true);

            NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            manager.createNotificationChannel(channel);
            mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
        }else{
            mBuilder = new NotificationCompat.Builder(this);
        }

        mBuilder.setSmallIcon(R.drawable.ic_stat_name)
                        .setContentTitle("ApduService")
                        .setContentText("processCommandApdu")
                        .setColor(Color.rgb(0,255,0))
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setAutoCancel(true)
                        .setWhen(System.currentTimeMillis())
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setVibrate(new long[]{100, 0, 100, 0, 100, 0});

        NotificationManagerCompat manager = NotificationManagerCompat.from(this);
        manager.notify(ID, mBuilder.build());
    }
}

References

[Android] Notify Alarm with NotificationManager https://akira-watson.com/android/alarm-notificationmanager.html

I tried a little with the behavior of the notification channel of Android by changing the targetSDKVersion of the project http://woshidan.hatenablog.com/entry/2017/08/23/083000

Customize Android notifications (API21 or later) https://qiita.com/sakebook/items/8cafc0766b4f8dc95994

[Android] Customize notifications! http://www.eda-inc.jp/post-622/

Try using the Android O notification channel http://blog.techium.jp/entry/2017/09/11/090000

Solved the problem that the notification icon became white on Android 5.0 Lolipop and above https://qiita.com/syarihu/items/95788cbab9b63100c4fb

How to send a notification to the status bar with the Android app. https://qiita.com/steroid66/items/27f5ce27eb32eae49732

Recommended Posts

Sample to display (head-up) notifications on Android
Sample to get WiFi, Bluetooth beacon, sensor information on Android
Android Development-Try to display a dialog-
How to "hollow" View on Android
I want to display background-ground-image on heroku.
How to detect microphone conflicts on Android
Pre-processing to display on the browser (compiler)
How to send push notifications on AWS
[Ruby on Rails] How to display error messages
[Android] Implement a function to display passwords quickly
(Android) Try to display static text using DataBinding
[Java] 4 steps to implement splash screen on Android
What to do if TextToSpeech doesn't work on Android 11
[Android] Display images and characters on the ViewPager tab
[For beginners] Minimum sample to display RecyclerView in Java
[Android Studio] I want to use Maven library on Android
[Introduction] Display Android Studio Hello World on the emulator
I want to simplify the log output on Android
Until the Google Assistant sample runs on Android Things
[Android] Notes on xml
Introduction to Android Layout
[Android] Review dialog display
I tried adding a separator line to TabLayout on Android
How to use OpenCV 4 on Android and view camera live view
Java source sample (Oracle Database + java) to SELECT and display CLOBs
Android app to select and display images from the gallery
From Ruby on Rails error message display to Japanese localization
Sample to create one-time password on server side and client side
How to display a graph in Ruby on Rails (LazyHighChart)
I'm glad to have a method to blink characters on Android
How to implement one-line display of TextView in Android development
Run the sample "Introduction to TensorFlow Development" on Jetson nano
Tips around the sample to release Java Lambda on CodePipeline
Until Android Studio beginners display "Hello World" on HUAWEI nova 2
Zip and upload multiple files to Firebase Storage on Android.
[Android] Try to display the effect on the touched part of the screen, which is common in games.