Share
Embed
What's new in Android 14 - IO Extended George Town 2023
Somkiat Khitwongwattana
June 28, 2023
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
49 slides
-
New features and APIs that are available in Android 14
System changes that might affect your app when it's running on Android 14 New Feature All Apps Targeting 14 Behavior Changes -
Targeting API Level 34 // build.gradle (module) android { compileSdk
34 defaultConfig { targetSdk 34 } } -
Sharesheet improvement 1. Add custom actions 2. Updated preview UI
3. Improve ranking quality with Direct Share targets New Feature User Experience -
Sharesheet improvement Add custom actions val actions: Array<ChooserAction> = /*
... */ val intent = Intent(/* ... */).apply { /* ... */ putExtra(Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS, actions) } Intent.createChooser(intent, "Chooser title") New Feature User Experience -
Predictive Back Built-in and custom animations Multiple improvements and new
guidance for Predictive Back New Feature User Experience -
Predictive Back Per activity opt-in <manifest> <application> <activity android:name=" MainActivity"
android:enableOnBackInvokedCallback="true" /> <activity android:name=" SecondActivity" android:enableOnBackInvokedCallback="false" /> </application> </manifest> New Feature User Experience -
Predictive Back Custom in-app transitions and animations override fun onCreate(savedInstanceState:
Bundle?) { /* ... */ val callback = object : OnBackPressedCallback(enabled = true) { override fun handleOnBackProgressed(backEvent: BackEvent) { // Transform animation } override fun handleOnBackPressed() { /* ... */ } override fun handleOnBackCancelled() { /* ... */ } } this.onBackPressedDispatcher.addCallback(callback) } New Feature User Experience -
Predictive Back Material components • Bottom sheets • Side sheets
• Search New Feature User Experience -
Detecting Screenshots Lets apps register callbacks on a per-activity basis.
And the user is notified, when the user takes a screenshot while that activity is visible. New Feature User Experience -
Detecting Screenshots // Activity val screenCaptureCallback = Activity.ScreenCaptureCallback { //
Add logic to take action in your app. } override fun onStart() { registerScreenCaptureCallback(mainExecutor, screenCaptureCallback) } override fun onStop() { unregisterScreenCaptureCallback(screenCaptureCallback) } New Feature User Experience -
Grant partial access to photos and videos User can grant
partial access to their photos and videos when an app requests any visual media permissions that were introduced in Android 13. Behavior Changes: All Apps User Experience -
Grant partial access to photos and videos Consider declaring the
new READ_MEDIA_VISUAL_USER_SELECTED permission, or use the photo picker in AndroidX Activity library. Behavior Changes: All Apps User Experience -
Secure full-screen Intent notifications Behavior Changes: All Apps Apps allowed
to use USE_FULL_SCREEN_INTENT permission are limited to those that provide calling or alarms only. And users can turn this permission on and off. To support this changes • Use NotificationManager.canUseFullScreenIntent to check the permission. • Use ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT to launch the settings page. User Experience -
Changes to how users experience non-dismissable notifications The notification that
set • Notification.Builder#setOngoing(true) • NotificationCompat.Builder#setOngoing(true) to prevent users dismissing foreground notification will be dismissable by the user. Behavior Changes: All Apps User Experience -
Changes to how users experience non-dismissable notifications Except: • When
the phone is locked • User selects a Clear all notification action • Notifications tied to real calls using CallStyle • Notifications created using MediaStyle Behavior Changes: All Apps User Experience -
Data safety information is more visible The system runtime permission
dialog now includes a clickable section that highlights your app's data sharing practices for some permission. Behavior Changes: All Apps User Experience -
Data safety information is more visible Behavior Changes: All Apps
System notification that appears when some installed apps change their data sharing to the third party or ads-related purpose. User Experience -
Per-app language preferences Automatic per-app language preferences // Android Studio
Giraffe Canary 7 or higher // AGP 8.1.0-alpha07 or higher android { androidResource { generateLocaleConfig true } } New Feature Internationalization -
Per-app language preferences Dynamic updates for different language sets val
localeManager = context.getSystemService(LocaleManager::class.java) localeManager.overrideLocaleConfig = LocaleConfig( LocaleList.forLanguageTags(regional_locales) ) New Feature Internationalization -
Grammatical Inflection API Lets you add support for grammatical gender
without refactoring your app. • feminine • masculine • neuter New Feature Internationalization -
Regional preferences Enable users to personalize temperature units, the first
day of the week, and numbering systems. New Feature Internationalization -
Regional preferences // androidx.core:core-ktx:1.12.0-alpha01 or higher val temperatureUnit = LocalePreferences.getTemperatureUnit()
// LocalePreferences.TemperatureUnit.CELSIUS // ... val firstDayOfWeek = LocalePreferences.getFirstDayOfWeek() // FirstDayOfWeek.SUNDAY // ... New Feature Internationalization -
Minimum installable target API level Behavior Changes: All Apps Apps
with a targetSdkVersion lower than 23 can't be installed. Requiring apps to meet these minimum target API level requirements improves security and privacy for users. // build.gradle (module) android { defaultConfig { targetSdk 22 } } Security -
Media owner package names might be redacted The value of
OWN_PACKAGE_NAME column in media store is redacted unless at least one of the following condition is true: • App that stored the media file has a package name that is always visible to other apps. • App that queries the media store requests the QUERY_ALL_PACKAGES permission. Behavior Changes: All Apps Security -
Restrictions to implicit and pending intents Behavior Changes: Targeting 34
Restricts apps from sending implicit intents to internal app components in the following ways: • Implicit intents are only delivered to exported components. • Mutable pending intent that doesn't specify a component or package Security -
Restrictions to implicit and pending intents <activity android:name=".AppActivity" android:exported="false"> <intent-filter>
<action android:name="com.example.action.APP_ACTION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> Behavior Changes: Targeting 34 Security -
Restrictions to implicit and pending intents // Throws an exception
when targeting Android 14. context.startActivity(Intent("com.example.action.APP_ACTION")) // This makes the intent explicit. val intent = Intent("com.example.action.APP_ACTION").apply { setPackage(context.packageName) } context.startActivity(intent) Behavior Changes: Targeting 34 Security -
Runtime-registered broadcasts receivers must specify export behavior val broadcastReceiver: BroadcastReceiver
= /* ... */ val intentFilter: IntentFilter = /* ... */ context.registerReceiver( broadcastReceiver, intentFilter, Context.RECEIVER_EXPORTED // or Context.RECEIVER_NOT_EXPORTED ) Behavior Changes: Targeting 34 Security -
Safer dynamic code loading All dynamically-loaded files must be marked
as read-only. val jar = File("DYNAMICALLY_LOADED_FILE.jar") FileOutputStream(jar).use { // Set the file to read-only first to prevent race conditions jar.setReadOnly() // Then write the actual file content } val pathClassLoader = PathClassLoader(jar, parentClassLoader) Behavior Changes: Targeting 34 Security -
Safer dynamic code loading Deleting and recreating the files before
you try to dynamically load them again in your app. Alternatively, verify the integrity of the files and re-label the existing files as read-only Behavior Changes: Targeting 34 Security -
Using ZipFile(String) and ZipInputStream.getNextEntry() with zip file entry names containing
.. or start with / will throw a ZipException . Or calling dalvik.system.ZipPathValidator.clearCallback() to opt-out from this validation. Zip path traversal Behavior Changes: Targeting 34 Security -
Additional restrictions on starting activities from the background The system
further restricts when apps are allowed to start activities from the background. • Sends a PendingIntent using PendingIntent#send() and wants to grant its own privileges to start the pending intent. • A visible app binds a service of another app that's in the background using the bindService() method and want to grant its own privileges to the bound service. Behavior Changes: Targeting 34 Security -
Paths are now queryable and interpolatable New Feature val path
= Path().apply { moveTo(1.0f, 1.0f) lineTo(2.0f, 2.0f) close() } val pathIterator = path.pathIterator for (segment in pathIterator) { println("segment: ${segment.verb}, ${segment.points}") } Graphic -
Paths are now queryable and interpolatable val interpolatedResult = Path()
if (path.isInterpolatable(otherPath)) { path.interpolate(otherPath, .5f, interpolatedResult) } New Feature Graphic -
Non-linear font scaling to 200% To prevent large text elements
on screen from scaling too large, the system applies a non-linear scaling curve New Feature Behavior Changes: All Apps Accessibility -
Non-linear font scaling to 200% New Feature Behavior Changes: All
Apps • Test your app with non-linear font scaling • Open the Settings app and navigate to Accessibility > Display size and text • Use scaled pixel (sp) units for text-sizes • Convert scaled pixel (sp) units • Use TypedValue.applyDimension() to convert from sp units to pixels • Use TypedValue.deriveDimension() to convert pixels to sp Accessibility -
Schedule exact alarms are denied by default Behavior Changes: All
Apps The SCHEDULE_EXACT_ALARM permission is no longer being pre-granted, the permission is denied by default. • Targets Android 13 (API level 33) or higher • Declares the SCHEDULE_EXACT_ALARM permission in the manifest • Isn't a calendar or alarm clock app • Doesn't fall under an exemption or pre-grant scenario Core Functionality -
Schedule exact alarms are denied by default Behavior Changes: All
Apps val manager: AlarmManager = context.getSystemService(AlarmManager::class.java) when { manager.canScheduleExactAlarms() -> { // If permission is granted, proceed with scheduling exact alarms manager.setExact(...) } else -> { // Ask users to go to exact alarm page in system settings startActivity(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)) } } Core Functionality -
Apps can kill only their own background processes Behavior Changes:
All Apps ActivityManager#killBackgroundProcesses method can kill only the background processes of your own app Core Functionality -
Foreground service types are required Behavior Changes: Targeting 34 Specify
at least one foreground service type for each foreground service within your app <manifest ...> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> <application ...> <service android:name=".LocationTrackingService" android:exported="false" android:foregroundServiceType="location" /> </application> </manifest> Core Functionality -
Foreground service types are required Behavior Changes: Targeting 34 •
FOREGROUND_SERVICE_CAMERA • FOREGROUND_SERVICE_LOCATION • FOREGROUND_SERVICE_MEDIA_PLAYBACK • FOREGROUND_SERVICE_MICROPHONE • FOREGROUND_SERVICE_PHONE_CALL • etc. Core Functionality -
Enforcement of BLUETOOTH_CONNECT permission Enforces the BLUETOOTH_CONNECT permission when calling
the getProfileConnectionState() method in BluetoothAdapter for apps targeting Android 14 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> Behavior Changes: Targeting 34 Core Functionality -
OpenJDK 17 updates • Updated ~300 java.base classes • Text
Blocks • Pattern Matching for instanceOf • Sealed classes Behavior Changes: Targeting 34 New Feature • Changes to regular expressions • UUID handling Core Functionality -
Thank You! Somkiat Khitwongwattana Android GDE @akexorcist More about Android
14 https://developer.android.com/about/versions/14