Part of the pit and corresponding solution for Android 8.0

Source: Internet
Author: User

Although Android 9.0 has already been published, this article is a little late to write.
But it's not easy to be late, so here's a record of how the Android 8.0 pits and solutions are encountered in the project.

Every time the system is upgraded, the system is more powerful and the performance is improved.

But for developers, a troubled problem comes with it--compatible.

Especially for some already-listed apps, before the new system is released, you need to know what changes are in order to prevent the app from running when the user upgrades the new system.

Okay, back to the theme, talk about some of the pits inside Android 8.0.

Can't recall the system installer

If your App provides updates, the user clicks on the update and the installation screen will automatically pop up after you download the APK.

The popup of this installation interface is dependent on the installer of the system.

Let's say your Android phone is under 8.0, but on a 8.0 phone, you'll find that it's completely unresponsive after downloading.

This time

Suppose you think it's a hint for the user to install, I'd say.

The user will not be able to ignore you. Users will not be updated in minutes.

So we have to solve this problem. Let this installer on Android 8.0 phone also can evoke normally.

In fact, the solution is very simple.

You only need to declare the following permissions in Androidmanifest.xml.

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

And do not need you in the code dynamic application, is not so easy.

A single line of code addresses this compatibility issue.

Notification issues

Let's say your App needs to show notifications on the taskbar. If you're following Android 8.0. Then you can't show up on the 8.0 phone.

What about that?

The basic wording of the notice here is no longer redundant, if not clear of the small partners to consult their own information. Here is the key to the solution.

Let's start with a few variables that appear in the following code:

private static NotificationManager manager;public static final String NOTIFICATION_CHANNEL = "your app pkg name";private static final String NOTIFICATION_CHANNEL_NAME = "App Channel";

The first one to write a notification knows that a management class.
The second is a CHANNEL of notification, which was introduced after 8.0. Value APP package name.
The third customization, as long as the only guarantee.

Compatibility has two steps to take action.

1. Create Channel
private static void createChannel() {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            NotificationChannel notifyChannel = new NotificationChannel(NOTIFICATION_CHANNEL,                    NOTIFICATION_CHANNEL_NAME,                    NotificationManager.IMPORTANCE_DEFAULT);            notifyChannel.setLightColor(Color.GREEN);            notifyChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);            manager.createNotificationChannel(notifyChannel);        }    }
2. Get Notification.builder
private Notification.Builder getNotificationBuilder(Context sourceContext) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            return new Notification.Builder(sourceContext, NOTIFICATION_CHANNEL);        } else {            return new Notification.Builder(sourceContext);        }    }

As you can see, the above operations are treated with 8.0 as the demarcation.

After these two steps, the App that can't show the notification can be displayed.

For more information, see official examples:
github.com/googlesamples/android-notificationchannels/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.