Android Platform Samples
repository·main·Indexed 23 days ago
https://github.com/android/platform-samplesA collection of Android OS platform API samples designed to showcase specific functionalities in isolation. The repository includes demonstrations for Accessibility, Camera2 API (including UltraHDR), Connectivity (BLE, Companion Device Manager, Telecom SDK, and UWB), Graphics (PdfRenderer and UltraHDR), Location, Privacy, Storage, and User-interface.
What's inside android-platform-samples
- The Jetpack WindowManager library provides a common API surface for accessing Window Manager features across different Android platform versions. It is designed to help applications support new device form factors, such as foldable devices, by providing consistent access to display information and window features. This sample specifically focuses on implementing support for foldables.
Overview of UltraHDR Media Samples
mainThis repository provides a catalog of media-related UltraHDR samples designed to demonstrate the usage and capabilities of UltraHDR images on the Android Platform. These samples serve as practical implementations of the UltraHDR HDR specifications.Overview of AppWidgets samples
mainThis module provides demonstration code for building Android AppWidgets using two primary approaches:
- RemoteViews and New Widgets APIs: Demonstrates the APIs introduced in Android 12 (API level 31) along with
core-remoteviewsfor building engaging widgets. - Jetpack Glance: Demonstrates how to use the Jetpack Glance framework to build app widgets.
Use these samples in conjunction with the official App widget guides.
- RemoteViews and New Widgets APIs: Demonstrates the APIs introduced in Android 12 (API level 31) along with
Overview of the Telecom Sample
mainThe Telecom Sample demonstrates how to integrate the Jetpack Telecom SDK to perform audio and/or video calls using the Android Telecom stack.
Note on Call Simulation: This sample simulates a caller application. It does not make actual phone calls; instead, it uses
AudioLoopSourceto capture device audio and loop it back to the active endpoint (such as the speaker) to simulate a call environment.Overview of Quick Settings tiles
mainQuick Settings are interactive tiles displayed in the status bar drawer above the notification shade. Apps can implement custom tiles that users can add to their Quick Settings panel.
This specific sample focuses on the most common implementation: a tile that users tap to toggle between an active and inactive state. For more complex tile types, refer to the official Android documentation on Create custom Quick Settings tiles for your app.
Overview of CallNotificationSample
mainTheCallNotificationSampleprovides implementation examples for posting both 'call' and 'in-call' notifications on Android. These notifications are subject to specific requirements regarding style and priority to ensure they behave correctly within the system's calling UI.Overview of Privacy - Data minimization samples
mainThis module provides sample implementations demonstrating how to implement data minimization principles in Android applications. Specifically, it focuses on two areas:
- Minimizing Package Visibility: Using Package Visibility APIs to limit the visibility of other installed apps on the device.
- Using Appropriate Identifiers: Implementing best practices for identifiers to avoid the use of non-resettable device identifiers.
Refer to
src/main/java/com/example/platform/privacy/data/PackageVisibility.ktfor specific implementation details regarding package visibility.Overview of UltraHDR Graphics Samples
mainThis repository contains a catalog of graphics-related UltraHDR samples designed to demonstrate the usage and capabilities of UltraHDR images on the Android Platform. Note that these samples are currently a work-in-progress.Overview of the Android Ultra-wideband (UWB) sample
mainThis sample project demonstrates the capabilities of the Android UWB Jetpack library. It provides concrete code examples for integrating UWB into Android applications, focusing on ranging and device interaction.
Key features demonstrated include:
- Device compatibility: Checking if a device supports UWB hardware.
- Device Discovery: Using an Out-of-Band (OOB) mechanism (specifically the Nearby Connections API) to discover devices, as UWB does not support native discovery.
- Simple Ranging: Displaying the distance between a controller and a controlee.
- Device Control: Simulating proximity-based actions, such as opening a door lock.
- Share Media: Demonstrating media file transfers using the selected OOB mechanism when devices are in close proximity.
- Role Selection: Configuring which device acts as the Controller or the Controlee.
Explore Storage API samples
mainThis directory contains sample implementations demonstrating how to use Android Storage APIs. The samples are designed to be independent of one another and provide simplified use cases for learning purposes.
Available samples:
- MediaStore Query: Demonstrates how to query the
MediaStoreto retrieve media files. - Selected Photos Access: Demonstrates how to handle partial access to photos (the Selected Photos Access feature).
For comprehensive documentation and production-ready implementation details, refer to the official Android Data Storage guide.
- MediaStore Query: Demonstrates how to query the
Understand the Platform Samples app module
mainThe
appmodule serves as the central launch point for the Android Platform Samples repository. It uses thecasa-androidframework to wire various individual samples together into a single application.Note for developers: The code within this specific module is infrastructure-related and is not intended to be modified or used directly when working on individual samples. You should focus on the specific sample modules rather than the
appmodule itself.Explore Drag and Drop implementation samples
mainThis directory contains several independent samples demonstrating different ways to implement Drag and Drop functionality in Android. Each sample is self-contained and can be run independently.
Available implementation patterns:
- Views-based: Uses
onLongClickListenerandDragListenercallbacks for basic implementation. - Multi-Window: Demonstrates drag-and-drop functionality across different applications.
- Jetpack Library: Uses the
Jetpack Drag and Drop Libraryfor implementation. - Jetpack Compose: Showcases drag-and-drop implementation specifically for Compose-based UIs.
- Rich Media: Demonstrates handling rich media using the
RichContentReceiverunified API, which works across drag-and-drop, keyboard, and clipboard operations.
- Views-based: Uses