Notes on Android 8.0 in the code

Keywords: Android Windows

1, Cancel most static registration broadcasts

Today, when I was doing the download task, I monitored the download progress through the broadcast. It was normal in 7.0, but running on 8.0, it failed. After checking, I found that 8.0 started to cancel most of the broadcast static registration

1. Register dynamically on the page to be monitored

      IntentFilter filter = new IntentFilter();
      mUpdateAppReceiver = new UpdateAppReceiver();
      registerReceiver(mUpdateAppReceiver, filter);

2. When the page is destroyed (ondestore()), remember to cancel listening

    public void onDestroy() {

3. Send broadcast. The action must be the same as the action when registering

    private static void sendProgress(Context context, int progress, String downloadMsg) {
         Intent intent = new Intent();
         intent.putExtra("progress", progress);
         intent.putExtra("downloadMsg", downloadMsg);


2, The usage of Notification and 8.0 is slightly different from that before, and the settings must be judged separately

String id = "channel_01";
String name = "Channel name";
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//Android 8.0 settings
    NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
    notification = new Notification.Builder(this)
            .setContentTitle("Downloading " + versionName)
            .setProgress(100, progress, false)
} else {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle("Downloading " + versionName)
            .setProgress(100, progress, false)
            .setOngoing(true) // If Ongoing is set to true, notification will not be able to slide delete
    //      . builder. Setautoconcel (true); / / after setting autoconcel to true, when you click notification in the notification bar, it will be automatically cancelled and disappear
    notification =;
nm.notify(notifyId, notification);
//Cancellation notice
private void cancelNotificaion() {
    if (nm != null) nm.cancel(notifyId);


3, If sd card is needed, and photo taking is limited, you must apply for permission manually, otherwise you cannot use it


4, Other new features of 8.0, such as support for multiple windows and adaptive icons (no need to adapt the image). For details, please see another friend's

New features of Android 8.0




Posted by Derleek on Sun, 26 Jan 2020 06:55:40 -0800