0

For example, I now have a program like Figure 1 (based on Android O):

enter image description here

Then I tried to write a notification function, and found a NotificationChannel object, but after writing it, like figure two

enter image description here,

when I removed the if, I would make a mistake on the cell phone below Android O, because I couldn't find this class.
Then Android O's notice also added a setTimeoutAfter (2000) method to set the notification disappear delay. This method didn't exist before Android O, but this method didn't add if limit, and it didn't report the error when running on the cell phone below Android O. I want to know why this is? Why does NotificationChannel make a mistake, and setTimeoutAfter doesn't make a mistake.

Or, as the title, Android compiler, I think I was determined with the 26 source code version, then run to each low version of the mobile phone, the mobile phone also should be each own version, I wonder why is setTimeoutAfter this method can perform (and no effect), rather than the exception.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
kyle
  • 11
  • 1
  • Your if statement surrounding that code prevents any of it from running... What's the exception you're getting? – OneCricketeer Dec 14 '17 at 02:32
  • Please don't post images of code; they're useless here. See [this Meta post](https://meta.stackoverflow.com/a/285557/62576) for a list of the many reasons to avoid doing so. Code is text, and can be easily copied and pasted into your question in that form. Images should only be used when there is no other way to demonstrate a problem. – Ken White Dec 14 '17 at 02:39
  • Your `setTimeoutAfter` maybe [NotificationCompat.Builder.setTimeoutAfter()](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setTimeoutAfter(long)). – Toris Dec 14 '17 at 02:42
  • you are right ,Toris,why NotificationCompat.Builder.setTimeoutAfter () can be compatible but NotificationChannel can‘t be compatible? – kyle Dec 14 '17 at 02:49
  • I'm sorry, I don't know that I can't use pictures – kyle Dec 14 '17 at 02:51
  • NotificationCompat.Builder is android.support.v4.app.NotificationCompat.Builder, and support-v4 is designed to work with API9. – Toris Dec 14 '17 at 03:00
  • @Toris,Why it is not wrong to run 'NotificationCompat.Builder.setTimeoutAfter()' in the device under Android O,only No response – kyle Dec 14 '17 at 03:08
  • My English is very poor,so....sorry – kyle Dec 14 '17 at 03:09
  • When running NotificationCompat.Builder.setTimeoutAfter in a device less than Android O, the source code used is the source code of the current device, such as android-21. When running to setTimeoutAfter, the system will decide if there is no such method, will it skip right? – kyle Dec 14 '17 at 03:17
  • 'var mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, id)',Android-21 does not have this construction method, so what does the system do when it runs to my code? – kyle Dec 14 '17 at 03:19
  • NotificationCompat.Builder is a builder for NotificationCompat, as name shows, and NotificationCompat is a helper for accessing features in Notification. Notification is from API1, so support library uses such classes, I think. Even if no such class exists, support library uses similar classes or functions. – Toris Dec 14 '17 at 03:25

1 Answers1

0

compilesdkversion is a bottom line or more for any classes / functions in source codes, as it is used for compile.

minSdkVersion is a bottom line app can be installed to a device.

targetSdkVersion is for deciding compatibility behaviors on a device.

Build.* are basically run time values on a device.

Classes that have "Compat" in there names are designed to work with older platforms. NotificationCompat.Builder.setTimeoutAfter() is one of these.


Related articles:

From question What is the difference between compileSdkVersion and targetSdkVersion?

  • compilesdkversion

    The compileSdkVersion property specifies the compilation target.

From Guide - App manifest - uses-sdk

  • minSdkVersion

    An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute.

  • targetSdkVersion

    This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

From Build class reference

  • Build

    Information about the current build, extracted from system properties.


Related question for NotificationCompat.Builder:

How to create a notification with NotificationCompat.Builder?

NB: NotificationCompat.Builder is a class of support-v4 library.
support-v4 library was for devices >= API4, as name shows. (Current document says it's for API9.)

Toris
  • 2,348
  • 13
  • 16