Android 17 כולל תכונות חדשות וממשקי API חדשים ושימושיים למפתחים. בקטעים הבאים מופיע סיכום של התכונות האלה שיעזור לכם להתחיל להשתמש בממשקי ה-API שקשורים אליהן.
רשימה מפורטת של ממשקי API חדשים, ממשקי API שעברו שינוי וממשקי API שהוסרו מופיעה בדוח השוואה בין גרסאות של API. פרטים על ממשקי API חדשים זמינים בהפניית Android API. ממשקי API חדשים מסומנים כדי להקל על האיתור שלהם.
כדאי גם לבדוק תחומים שבהם שינויים בפלטפורמה עשויים להשפיע על האפליקציות שלכם. למידע נוסף, ראו את הדפים הבאים:
- שינויים בהתנהגות שמשפיעים על אפליקציות שמטרגטות ל-Android 17
- שינויים בהתנהגות שמשפיעים על כל האפליקציות בלי קשר ל-
targetSdkVersion.
פונקציונליות עיקרית
Android 17 מוסיפה את התכונות החדשות הבאות שקשורות לפונקציונליות הליבה של Android.
טריגרים חדשים של ProfilingManager
ב-Android 17 נוספו כמה טריגרים חדשים של המערכת ל-ProfilingManager כדי לעזור לכם לאסוף נתונים מפורטים לניפוי באגים בבעיות ביצועים.
הטריגרים החדשים הם:
-
TRIGGER_TYPE_COLD_START: הטריגר מופעל במהלך הפעלה קרה של האפליקציה. התשובה כוללת דוגמה למחסנית קריאות ומעקב מערכת. -
TRIGGER_TYPE_OOM: הטריגר מופעל כשאפליקציה יוצרתOutOfMemoryErrorומספקת בתגובה Java Heap Dump. -
TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE: הטריגר מופעל כשאפליקציה נסגרת בגלל שימוש חריג ומוגזם במעבד, ומספק דגימה של מחסנית הקריאות בתגובה.
כדי להבין איך להגדיר את טריגר המערכת, אפשר לעיין בתיעוד בנושא יצירת פרופילים שמבוססת על טריגרים ובתיעוד בנושא אחזור וניתוח של נתוני פרופילים.
ממשקי JobDebugInfo API
ב-Android 17 נוספו ממשקי API חדשים של JobDebugInfo כדי לעזור למפתחים לנפות באגים במשימות של JobScheduler – למה הן לא פועלות, כמה זמן הן פעלו ומידע מצטבר אחר.
השיטה הראשונה של ממשקי JobDebugInfo API המורחבים היא getPendingJobReasonStats(), שמחזירה מפה של הסיבות לכך שהעבודה הייתה במצב של ביצוע בהמתנה ומשך ההמתנה המצטבר שלהן. השיטה הזו מצטרפת לשיטות getPendingJobReasonsHistory() ו-getPendingJobReasons() כדי לספק לכם תובנות לגבי הסיבה לכך שעבודה מתוזמנת לא פועלת כמצופה, אבל היא מפשטת את אחזור המידע בכך שהיא מאפשרת לקבל את משך הזמן ואת הסיבה לעבודה בשיטה אחת.
לדוגמה, עבור jobId שצוין, יכול להיות שהשיטה תחזיר את PENDING_JOB_REASON_CONSTRAINT_CHARGING ואת משך הזמן 60,000 אלפיות השנייה, מה שמציין שהעבודה הייתה בהמתנה במשך 60,000 אלפיות השנייה כי לא התקיים התנאי של הטעינה.
פרטיות
Android 17 כוללת את התכונות החדשות הבאות לשיפור הפרטיות של המשתמשים.
הכלי לבחירת אנשי קשר ב-Android
The Android Contact Picker is a standardized, browsable interface for users to
share contacts with your app. Available on devices running
Android 17 or higher, the picker offers a privacy-preserving
alternative to the broad READ_CONTACTS permission. Instead of requesting
access to the user's entire address book, your app specifies the data fields it
needs, such as phone numbers or email addresses, and the user selects specific
contacts to share. This grants your app read access to only the selected data,
ensuring granular control while providing a consistent user experience with
built-in search, profile switching, and multi-selection capabilities without
having to build or maintain the UI.
For more information, see the contact picker documentation.
אבטחה
ב-Android 17 נוספו התכונות החדשות הבאות לשיפור האבטחה של המכשיר והאפליקציות.
מצב ההגנה המתקדמת ב-Android (AAPM)
Android Advanced Protection Mode offers Android users a powerful new set of security features, marking a significant step in safeguarding users—particularly those at higher risk—from sophisticated attacks. Designed as an opt-in feature, AAPM is activated with a single configuration setting that users can turn on at any time to apply an opinionated set of security protections.
These core configurations include blocking app installation from unknown sources
(sideloading), restricting USB data signaling, and mandating Google Play Protect
scanning, which significantly reduces the device's attack surface area.
Developers can integrate with this feature using the
AdvancedProtectionManager API to detect the mode's status, enabling
applications to automatically adopt a hardened security posture or restrict
high-risk functionality when a user has opted in.
קישוריות
ב-Android 17 נוספו התכונות הבאות לשיפור הקישוריות של המכשיר והאפליקציה.
רשתות לוויין מוגבלות
מבצעת אופטימיזציות כדי לאפשר לאפליקציות לפעול ביעילות ברשתות לווייניות עם רוחב פס נמוך.
חוויית המשתמש וממשק המשתמש של המערכת
Android 17 כוללת את השינויים הבאים לשיפור חוויית המשתמש.
הפעלה רציפה
התכונה Handoff היא תכונה חדשה ו-API חדש שיושקו ב-Android 17. מפתחי אפליקציות יוכלו לשלב אותם כדי לספק למשתמשים שלהם המשכיות בין מכשירים. התכונה הזו מאפשרת למשתמש להתחיל פעילות באפליקציה במכשיר Android אחד ולהעביר אותה למכשיר Android אחר. התכונה'העברה חלקה' פועלת ברקע של המכשיר של המשתמש ומציגה פעילויות זמינות מהמכשירים הסמוכים האחרים של המשתמש דרך נקודות כניסה שונות, כמו מרכז האפליקציות וסרגל המשימות, במכשיר המקבל.
אפליקציות יכולות להגדיר את התכונה 'המשכיות' כדי להפעיל את אותה אפליקציית Android מקורית, אם היא מותקנת וזמינה במכשיר המקבל. בתהליך הזה של מעבר מאפליקציה לאפליקציה, המשתמש מועבר באמצעות קישור עומק לפעילות המיועדת. אפשרות אחרת היא להציע את ההעברה מאפליקציה לאתר כחלופה או להטמיע אותה ישירות באמצעות העברת כתובת URL.
התמיכה בהעברה בין מכשירים מקושרים מיושמת על בסיס כל פעילות בנפרד. כדי להפעיל את התכונה Handoff, צריך להריץ את השיטה setHandoffEnabled() לפעילות. יכול להיות שיהיה צורך להעביר נתונים נוספים עם ההעברה כדי שהפעילות שנוצרה מחדש במכשיר המקבל תוכל לשחזר את המצב המתאים. מטמיעים את הקריאה החוזרת (callback) onHandoffActivityRequested() כדי להחזיר אובייקט HandoffActivityData שמכיל פרטים שמציינים איך התכונה 'העברה מהירה' צריכה לטפל בפעילות וליצור אותה מחדש במכשיר המקבל.
Live Update - Semantic color API
With Android 17, Live Update launches the Semantic Coloring APIs to support colors with universal meaning.
The following classes support semantic coloring:
NotificationNotification.MetricNotification.ProgressStyle.PointNotification.ProgressStyle.Segment
Coloring
- Green: Associated with safety. This color should be used for the case where it lets people know you are in the safe situation.
- Orange: For designating caution and marking physical hazards. This color should be used in the situation where users need to pay attention to set better protection setting.
- Red: Generally indicates danger, stop. It should be presented for the case where need people's attention urgently.
- Blue: Neutral color for content that is informational and should stand out from other content.
The following example shows how to apply semantic styles to text in a notification:
val ssb = SpannableStringBuilder()
.append("Colors: ")
.append("NONE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_UNSPECIFIED), 0)
.append(", ")
.append("INFO", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_INFO), 0)
.append(", ")
.append("SAFE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_SAFE), 0)
.append(", ")
.append("CAUTION", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_CAUTION), 0)
.append(", ")
.append("DANGER", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_DANGER), 0)
Notification.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_icon)
.setContentTitle("Hello World!")
.setContentText(ssb)
.setOngoing(true)
.setRequestPromotedOngoing(true)
UWB Downlink-TDoA API for Android 17
Downlink Time Difference of Arrival (DL-TDoA) ranging lets a device determine its position relative to multiple anchors by measuring the relative arrival times of signals.
The following snippet demonstrates how to initialize the Ranging Manager, verify device capabilities, and start a DL-TDoA session:
Kotlin
class RangingApp {
fun initDlTdoa(context: Context) {
// Initialize the Ranging Manager
val rangingManager = context.getSystemService(RangingManager::class.java)
// Register for device capabilities
val capabilitiesCallback = object : RangingManager.CapabilitiesCallback {
override fun onRangingCapabilities(capabilities: RangingCapabilities) {
// Make sure Dl-TDoA is supported before starting the session
if (capabilities.uwbCapabilities != null && capabilities.uwbCapabilities!!.isDlTdoaSupported) {
startDlTDoASession(context)
}
}
}
rangingManager.registerCapabilitiesCallback(Executors.newSingleThreadExecutor(), capabilitiesCallback)
}
fun startDlTDoASession(context: Context) {
// Initialize the Ranging Manager
val rangingManager = context.getSystemService(RangingManager::class.java)
// Create session and configure parameters
val executor = Executors.newSingleThreadExecutor()
val rangingSession = rangingManager.createRangingSession(executor, RangingSessionCallback())
val rangingRoundIndexes = intArrayOf(0)
val config: ByteArray = byteArrayOf() // OOB config data
val params = DlTdoaRangingParams.createFromFiraConfigPacket(config, rangingRoundIndexes)
val rangingDevice = RangingDevice.Builder().build()
val rawTagDevice = RawRangingDevice.Builder()
.setRangingDevice(rangingDevice)
.setDlTdoaRangingParams(params)
.build()
val dtTagConfig = RawDtTagRangingConfig.Builder(rawTagDevice).build()
val preference = RangingPreference.Builder(DEVICE_ROLE_DT_TAG, dtTagConfig)
.setSessionConfig(SessionConfig.Builder().build())
.build()
// Start the ranging session
rangingSession.start(preference)
}
}
private class RangingSessionCallback : RangingSession.Callback {
override fun onDlTdoaResults(peer: RangingDevice, measurement: DlTdoaMeasurement) {
// Process measurement results here
}
}
Java
public class RangingApp {
public void initDlTdoa(Context context) {
// Initialize the Ranging Manager
RangingManager rangingManager = context.getSystemService(RangingManager.class);
// Register for device capabilities
RangingManager.CapabilitiesCallback capabilitiesCallback = new RangingManager.CapabilitiesCallback() {
@Override
public void onRangingCapabilities(RangingCapabilities capabilities) {
// Make sure Dl-TDoA is supported before starting the session
if (capabilities.getUwbCapabilities() != null && capabilities.getUwbCapabilities().isDlTdoaSupported) {
startDlTDoASession(context);
}
}
};
rangingManager.registerCapabilitiesCallback(Executors.newSingleThreadExecutor(), capabilitiesCallback);
}
public void startDlTDoASession(Context context) {
RangingManager rangingManager = context.getSystemService(RangingManager.class);
// Create session and configure parameters
Executor executor = Executors.newSingleThreadExecutor();
RangingSession rangingSession = rangingManager.createRangingSession(executor, new RangingSessionCallback());
int[] rangingRoundIndexes = new int[] {0};
byte[] config = new byte[0]; // OOB config data
DlTdoaRangingParams params = DlTdoaRangingParams.createFromFiraConfigPacket(config, rangingRoundIndexes);
RangingDevice rangingDevice = new RangingDevice.Builder().build();
RawRangingDevice rawTagDevice = new RawRangingDevice.Builder()
.setRangingDevice(rangingDevice)
.setDlTdoaRangingParams(params)
.build();
RawDtTagRangingConfig dtTagConfig = new RawDtTagRangingConfig.Builder(rawTagDevice).build();
RangingPreference preference = new RangingPreference.Builder(DEVICE_ROLE_DT_TAG, dtTagConfig)
.setSessionConfig(new SessionConfig.Builder().build())
.build();
// Start the ranging session
rangingSession.start(preference);
}
private static class RangingSessionCallback implements RangingSession.Callback {
@Override
public void onDlTdoaResults(RangingDevice peer, DlTdoaMeasurement measurement) {
// Process measurement results here
}
}
}
Out-of-Band (OOB) Configurations
The following snippet provides an example of DL-TDoA OOB configuration data for Wi-Fi and BLE:
Java
// Wifi Configuration
byte[] wifiConfig = {
(byte) 0xDD, (byte) 0x2D, (byte) 0x5A, (byte) 0x18, (byte) 0xFF, // Header
(byte) 0x5F, (byte) 0x19, // FiRa Sub-Element
(byte) 0x02, (byte) 0x00, // Profile ID
(byte) 0x06, (byte) 0x02, (byte) 0x20, (byte) 0x08, // MAC Address
(byte) 0x14, (byte) 0x01, (byte) 0x0C, // Preamble Index
(byte) 0x27, (byte) 0x02, (byte) 0x08, (byte) 0x07, // Vendor ID
(byte) 0x28, (byte) 0x06, (byte) 0xCA, (byte) 0xC8, (byte) 0xA6, (byte) 0xF7, (byte) 0x6F, (byte) 0x08, // Static STS IV
(byte) 0x08, (byte) 0x02, (byte) 0x60, (byte) 0x09, // Slot Duration
(byte) 0x1B, (byte) 0x01, (byte) 0x0A, // Slots per RR
(byte) 0x09, (byte) 0x04, (byte) 0xE8, (byte) 0x03, (byte) 0x00, (byte) 0x00, // Duration
(byte) 0x9F, (byte) 0x04, (byte) 0x67, (byte) 0x45, (byte) 0x23, (byte) 0x01 // Session ID
};
// BLE Configuration
byte[] bleConfig = {
(byte) 0x2D, (byte) 0x16, (byte) 0xF4, (byte) 0xFF, // Header
(byte) 0x5F, (byte) 0x19, // FiRa Sub-Element
(byte) 0x02, (byte) 0x00, // Profile ID
(byte) 0x06, (byte) 0x02, (byte) 0x20, (byte) 0x08, // MAC Address
(byte) 0x14, (byte) 0x01, (byte) 0x0C, // Preamble Index
(byte) 0x27, (byte) 0x02, (byte) 0x08, (byte) 0x07, // Vendor ID
(byte) 0x28, (byte) 0x06, (byte) 0xCA, (byte) 0xC8, (byte) 0xA6, (byte) 0xF7, (byte) 0x6F, (byte) 0x08, // Static STS IV
(byte) 0x08, (byte) 0x02, (byte) 0x60, (byte) 0x09, // Slot Duration
(byte) 0x1B, (byte) 0x01, (byte) 0x0A, // Slots per RR
(byte) 0x09, (byte) 0x04, (byte) 0xE8, (byte) 0x03, (byte) 0x00, (byte) 0x00, // Duration
(byte) 0x9F, (byte) 0x04, (byte) 0x67, (byte) 0x45, (byte) 0x23, (byte) 0x01 // Session ID
};
If you can't use an OOB configuration because it is missing, or if you need to
change default values that aren't in the OOB config, you can build parameters
with DlTdoaRangingParams.Builder as shown in the following snippet. You can use
these parameters in place of DlTdoaRangingParams.createFromFiraConfigPacket():
Kotlin
val dlTdoaParams = DlTdoaRangingParams.Builder(1)
.setComplexChannel(UwbComplexChannel.Builder()
.setChannel(9).setPreambleIndex(10).build())
.setDeviceAddress(deviceAddress)
.setSessionKeyInfo(byteArrayOf(0x01, 0x02, 0x03, 0x04))
.setRangingIntervalMillis(240)
.setSlotDuration(UwbRangingParams.DURATION_2_MS)
.setSlotsPerRangingRound(20)
.setRangingRoundIndexes(byteArrayOf(0x01, 0x05))
.build()
Java
DlTdoaRangingParams dlTdoaParams = new DlTdoaRangingParams.Builder(1)
.setComplexChannel(new UwbComplexChannel.Builder()
.setChannel(9).setPreambleIndex(10).build())
.setDeviceAddress(deviceAddress)
.setSessionKeyInfo(new byte[]{0x01, 0x02, 0x03, 0x04})
.setRangingIntervalMillis(240)
.setSlotDuration(UwbRangingParams.DURATION_2_MS)
.setSlotsPerRangingRound(20)
.setRangingRoundIndexes(new byte[]{0x01, 0x05})
.build();