การเปลี่ยนแปลงลักษณะการทำงาน: แอปที่กำหนดเป้าหมายเป็น Android 16 ขึ้นไป

Android 16 มีการทํางานบางอย่างที่อาจส่งผลต่อแอปของคุณเช่นเดียวกับเวอร์ชันก่อนหน้า การเปลี่ยนแปลงลักษณะการทํางานต่อไปนี้มีผลกับแอปที่กําหนดเป้าหมายเป็น Android 16 ขึ้นไปเท่านั้น หากแอปกำหนดเป้าหมายเป็น Android 16 ขึ้นไป คุณควรแก้ไขแอปให้รองรับลักษณะการทำงานเหล่านี้ (หากมี)

นอกจากนี้ โปรดตรวจสอบรายการการเปลี่ยนแปลงลักษณะการทำงานที่ส่งผลต่อแอปทั้งหมดที่ทำงานบน Android 16 ไม่ว่า targetSdkVersion ของแอปจะเป็นอย่างไรก็ตาม

ประสบการณ์ของผู้ใช้และ UI ของระบบ

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงต่อไปนี้ซึ่งมีจุดประสงค์เพื่อสร้างประสบการณ์การใช้งานที่สม่ำเสมอและใช้งานง่ายยิ่งขึ้น

การเลิกใช้งานแบบเต็มหน้าจอจะหยุดให้บริการ

Android 15 บังคับใช้การแสดงผลแบบเต็มหน้าจอสำหรับแอปที่กำหนดเป้าหมายเป็น Android 15 (API ระดับ 35) แต่แอปของคุณเลือกไม่ใช้ได้โดยการตั้งค่า R.attr#windowOptOutEdgeToEdgeEnforcement เป็น true สําหรับแอปที่กําหนดเป้าหมายเป็น Android 16 (API ระดับ 36) ระบบจะเลิกใช้งานและปิดใช้ R.attr#windowOptOutEdgeToEdgeEnforcement และแอปจะเลือกไม่ใช้การแสดงแบบไร้ขอบไม่ได้

  • หากแอปกำหนดเป้าหมายเป็น Android 16 (API ระดับ 36) และทำงานในอุปกรณ์ Android 15 R.attr#windowOptOutEdgeToEdgeEnforcement จะยังคงทำงานต่อไป
  • หากแอปกำหนดเป้าหมายเป็น Android 16 (API ระดับ 36) และทำงานบนอุปกรณ์ Android 16 ระบบจะปิดใช้ R.attr#windowOptOutEdgeToEdgeEnforcement

สำหรับการทดสอบใน Android 16 Beta 3 โปรดตรวจสอบว่าแอปของคุณรองรับการแสดงผลแบบเต็มหน้าจอและนำการใช้ R.attr#windowOptOutEdgeToEdgeEnforcement ออกเพื่อให้แอปรองรับการแสดงผลแบบเต็มหน้าจอในอุปกรณ์ Android 15 ด้วย หากต้องการรองรับการแสดงผลแบบเต็มหน้าจอ โปรดดูคำแนะนำเกี่ยวกับการเขียนและมุมมอง

ต้องย้ายข้อมูลหรือเลือกไม่ใช้ฟีเจอร์การย้อนกลับแบบคาดคะเน

สําหรับแอปที่กําหนดเป้าหมายเป็น Android 16 ขึ้นไปและทํางานบนอุปกรณ์ Android 16 ขึ้นไป ระบบจะเปิดใช้ภาพเคลื่อนไหวการกลับไปยังระบบแบบคาดการณ์ (กลับไปยังหน้าจอหลัก ข้ามงาน และข้ามกิจกรรม) โดยค่าเริ่มต้น นอกจากนี้ ระบบจะไม่เรียกใช้ onBackPressed และจะไม่ส่ง KeyEvent.KEYCODE_BACK อีกต่อไป

หากแอปของคุณขัดจังหวะเหตุการณ์ "กลับ" และคุณยังไม่ได้ย้ายข้อมูลไปยัง "กลับ" แบบคาดการณ์ ให้อัปเดตแอปเพื่อใช้ API การนําทางกลับที่รองรับ หรือเลือกไม่ใช้ชั่วคราวโดยตั้งค่าแอตทริบิวต์ android:enableOnBackInvokedCallback เป็น false ในแท็ก <application> หรือ <activity> ของไฟล์ AndroidManifest.xml ของแอป

ภาพเคลื่อนไหวแบบคาดเดาซึ่งแสดงการกลับไปยังหน้าแรก
ภาพเคลื่อนไหวข้ามกิจกรรมแบบคาดเดา
ภาพเคลื่อนไหวข้ามงานที่คาดคะเน

เลิกใช้งานและปิดใช้ Elegant Font API

Apps targeting Android 15 (API level 35) have the elegantTextHeight TextView attribute set to true by default, replacing the compact font with one that is much more readable. You could override this by setting the elegantTextHeight attribute to false.

Android 16 deprecates the elegantTextHeight attribute, and the attribute will be ignored once your app targets Android 16. The "UI fonts" controlled by these APIs are being discontinued, so you should adapt any layouts to ensure consistent and future proof text rendering in Arabic, Lao, Myanmar, Tamil, Gujarati, Kannada, Malayalam, Odia, Telugu or Thai.

elegantTextHeight behavior for apps targeting Android 14 (API level 34) and lower, or for apps targeting Android 15 (API level 35) that overrided the default by setting the elegantTextHeight attribute to false.
elegantTextHeight behavior for apps targeting Android 16, or for apps targeting Android 15 (API level 35) that didn't override the default by setting the elegantTextHeight attribute to false.

ฟังก์ชันหลัก

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงต่อไปนี้ที่แก้ไขหรือขยายความสามารถหลักต่างๆ ของระบบ Android

การเพิ่มประสิทธิภาพการจัดกำหนดเวลางานแบบอัตราคงที่

Prior to targeting Android 16, when scheduleAtFixedRate missed a task execution due to being outside a valid process lifecycle, all missed executions immediately execute when the app returns to a valid lifecycle.

When targeting Android 16, at most one missed execution of scheduleAtFixedRate is immediately executed when the app returns to a valid lifecycle. This behavior change is expected to improve app performance. Test this behavior in your app to check if your app is impacted. You can also test by using the app compatibility framework and enabling the STPE_SKIP_MULTIPLE_MISSED_PERIODIC_TASKS compat flag.

รูปแบบของอุปกรณ์

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงต่อไปนี้สำหรับแอปเมื่อแสดงในอุปกรณ์หน้าจอขนาดใหญ่

เลย์เอาต์ที่ปรับเปลี่ยนได้

With Android apps now running on a variety of devices (such as phones, tablets, foldables, desktops, cars, and TVs) and windowing modes on large screens (such as split screen and desktop windowing), developers should build Android apps that adapt to any screen and window size, regardless of device orientation. Paradigms like restricting orientation and resizability are too restrictive in today's multidevice world.

Ignore orientation, resizability, and aspect ratio restrictions

For apps targeting Android 16 (API level 36), Android 16 includes changes to how the system manages orientation, resizability, and aspect ratio restrictions. On displays with smallest width >= 600dp, the restrictions no longer apply. Apps also fill the entire display window, regardless of aspect ratio or a user's preferred orientation, and pillarboxing isn't used.

This change introduces a new standard platform behavior. Android is moving toward a model where apps are expected to adapt to various orientations, display sizes, and aspect ratios. Restrictions like fixed orientation or limited resizability hinder app adaptability, so we recommend making your app adaptive to deliver the best possible user experience.

You can also test this behavior by using the app compatibility framework and enabling the UNIVERSAL_RESIZABLE_BY_DEFAULT compat flag.

Common breaking changes

Ignoring orientation, resizability, and aspect ratio restrictions might impact your app's UI on some devices, especially elements that were designed for small layouts locked in portrait orientation: for example, issues like stretched layouts and off-screen animations and components. Any assumptions about aspect ratio or orientation can cause visual issues with your app. Learn more about how to avoid them and improve your app's adaptive behaviour.

Allowing device rotation results in more activity re-creation, which can result in losing user state if not properly preserved. Learn how to correctly save UI state in Save UI states.

Implementation details

The following manifest attributes and runtime APIs are ignored across large screen devices in full-screen and multi-window modes:

The following values for screenOrientation, setRequestedOrientation(), and getRequestedOrientation() are ignored:

  • portrait
  • reversePortrait
  • sensorPortrait
  • userPortrait
  • landscape
  • reverseLandscape
  • sensorLandscape
  • userLandscape

Regarding display resizability, android:resizeableActivity="false", android:minAspectRatio, and android:maxAspectRatio have no effect.

For apps targeting Android 16 (API level 36), app orientation, resizability, and aspect ratio constraints are ignored on large screens by default, but every app that isn't fully ready can temporarily override this behavior by opting out (which results in the previous behavior of being placed in compatibility mode).

Exceptions

The Android 16 orientation, resizability, and aspect ratio restrictions don't apply in the following situations:

  • Games (based on the android:appCategory flag)
  • Users explicitly opting in to the app's default behavior in aspect ratio settings of the device
  • Screens that are smaller than sw600dp

Opt out temporarily

To opt out a specific activity, declare the PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY manifest property:

<activity ...>
  <property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />
  ...
</activity>

If too many parts of your app aren't ready for Android 16, you can opt out completely by applying the same property at the application level:

<application ...>
  <property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />
</application>

สุขภาพและการออกกำลังกาย

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงต่อไปนี้ที่เกี่ยวข้องกับข้อมูลสุขภาพและการออกกำลังกาย

สิทธิ์ด้านสุขภาพและการออกกำลังกาย

สำหรับแอปที่กำหนดเป้าหมายเป็น Android 16 ขึ้นไป สิทธิ์ BODY_SENSORS จะเปลี่ยนไปใช้สิทธิ์แบบละเอียดภายใต้ android.permissions.health ซึ่ง Health Connect จะใช้ด้วย ตอนนี้ API ใดก็ตามที่ก่อนหน้านี้ต้องใช้ BODY_SENSORS หรือ BODY_SENSORS_BACKGROUND ต้องใช้สิทธิ์ android.permissions.health ที่เกี่ยวข้อง ซึ่งจะส่งผลต่อประเภทข้อมูล, API และบริการที่ทำงานอยู่เบื้องหน้าต่อไปนี้

หากแอปของคุณใช้ API เหล่านี้ ตอนนี้แอปควรขอสิทธิ์แบบละเอียดต่อไปนี้

  • สําหรับการตรวจสอบอัตราการเต้นของหัวใจ, SpO2 หรืออุณหภูมิผิวขณะใช้งาน ให้ขอสิทธิ์แบบละเอียดในส่วน android.permissions.health เช่น READ_HEART_RATE แทน BODY_SENSORS
  • สําหรับสิทธิ์เข้าถึงเซ็นเซอร์ในเบื้องหลัง ให้ขอREAD_HEALTH_DATA_IN_BACKGROUND แทนBODY_SENSORS_BACKGROUND

สิทธิ์เหล่านี้เหมือนกับสิทธิ์ที่ปกป้องการเข้าถึงการอ่านข้อมูลจาก Health Connect ซึ่งเป็นที่เก็บข้อมูล Android สำหรับข้อมูลสุขภาพ การออกกำลังกาย และสุขภาวะ

แอปบนอุปกรณ์เคลื่อนที่

แอปบนอุปกรณ์เคลื่อนที่ที่ย้ายข้อมูลไปใช้ READ_HEART_RATE และสิทธิ์แบบละเอียดอื่นๆ จะต้องประกาศกิจกรรมเพื่อแสดงนโยบายความเป็นส่วนตัวของแอปด้วย ข้อกำหนดนี้เหมือนกับ Health Connect

การเชื่อมต่อ

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงต่อไปนี้ในกองซ้อนบลูทูธเพื่อปรับปรุงการเชื่อมต่อกับอุปกรณ์ต่อพ่วง

Intent ใหม่สำหรับจัดการการสูญเสียพันธบัตรและการเปลี่ยนแปลงการเข้ารหัส

การจัดการการสูญเสียการเชื่อมโยงที่ดีขึ้นทำให้ Android 16 เปิดตัว Intent ใหม่ 2 รายการเพื่อให้แอปรับรู้ถึงการสูญเสียการเชื่อมโยงและการเปลี่ยนแปลงการเข้ารหัสได้ดียิ่งขึ้น

ตอนนี้แอปที่กําหนดเป้าหมายเป็น Android 16 ทําสิ่งต่อไปนี้ได้

  • รับ Intent ACTION_KEY_MISSING เมื่อตรวจพบการสูญเสียการเชื่อมโยงระยะไกล ซึ่งช่วยให้สามารถแสดงความคิดเห็นที่เป็นประโยชน์ต่อผู้ใช้มากขึ้นและดำเนินการที่เหมาะสม
  • รับ Intent ACTION_ENCRYPTION_CHANGE เมื่อใดก็ตามที่สถานะการเข้ารหัสของลิงก์มีการเปลี่ยนแปลง ซึ่งรวมถึงการเปลี่ยนแปลงสถานะการเข้ารหัส การเปลี่ยนแปลงอัลกอริทึมการเข้ารหัส และการเปลี่ยนแปลงขนาดคีย์การเข้ารหัส แอปต้องถือว่าการเชื่อมโยงได้รับการกู้คืนหากลิงก์ได้รับการเข้ารหัสเรียบร้อยแล้วเมื่อได้รับ Intent ACTION_ENCRYPTION_CHANGE ในภายหลัง

หากปัจจุบันแอปของคุณใช้กลไกที่กำหนดเองสำหรับการจัดการการสูญเสียพันธบัตร ให้ย้ายข้อมูลไปยัง Intent ใหม่ ACTION_KEY_MISSING เพื่อตรวจหาและจัดการเหตุการณ์การสูญเสียพันธบัตร เราขอแนะนำให้แอปแนะนำผู้ใช้ให้ตรวจสอบว่าอุปกรณ์ระยะไกลอยู่ในระยะสัญญาณก่อนเริ่มการลืมอุปกรณ์และการจับคู่อีกครั้ง

นอกจากนี้ หากอุปกรณ์ตัดการเชื่อมต่อหลังจากได้รับ Intent ACTION_KEY_MISSING แอปของคุณควรคำนึงถึงการเชื่อมต่อกับอุปกรณ์อีกครั้ง เนื่องจากอุปกรณ์ดังกล่าวอาจไม่ได้เชื่อมโยงกับระบบแล้ว

ความปลอดภัย

Android 16 (API ระดับ 36) มีการเปลี่ยนแปลงด้านความปลอดภัยดังต่อไปนี้

การล็อกเวอร์ชัน MediaStore

สำหรับแอปที่กําหนดเป้าหมายเป็น Android 16 ขึ้นไป MediaStore#getVersion() จะมีลักษณะเฉพาะสำหรับแต่ละแอป ซึ่งจะนําพร็อพเพอร์ตี้ระบุออกจากสตริงเวอร์ชันเพื่อป้องกันการละเมิดและการใช้เทคนิคการระบุตัวตน แอปไม่ควรคาดเดารูปแบบของเวอร์ชันนี้ แอปควรจัดการการเปลี่ยนแปลงเวอร์ชันอยู่แล้วเมื่อใช้ API นี้ และในกรณีส่วนใหญ่ก็ไม่จำเป็นต้องเปลี่ยนแปลงลักษณะการทำงานปัจจุบัน เว้นแต่นักพัฒนาแอปจะพยายามอนุมานข้อมูลเพิ่มเติมที่อยู่นอกเหนือขอบเขตที่ตั้งใจไว้ของ API นี้