Todo el nuevo Android 12. Revisión para desarrolladores

Hola. Mi nombre es  Kirill Rozov  y si estás interesado en el desarrollo de Android, probablemente hayas oído hablar del  canal de Telegram "Android Broadcast" , con noticias diarias para desarrolladores de Android, y el  canal de YouTube del mismo nombre . Esta publicación es una transcripción de texto de un nuevo video en el canal.






Se llevó a cabo la conferencia de Google I / O y aprendimos absolutamente todo sobre la nueva versión de Android, y también puedes probar todo esto en Beta 1, que se puede instalar en el Pixel de forma inalámbrica, así como en varios otros fabricantes. le permite instalar la imagen GSI.





. , - . App Widgets , Android.





Material You

Google Material Design, . , Pixel . Material You Beta Android 12





: " Material You ?" Android, . Material , . . Google





Splash Screen ms

<item name="android:windowSplashScreenBackground">@color/...</item>
<item name="android:windowSplashScreenAnimatableIcon">@drawable/...</item>
<item name=”android:windowSplashScreenIconBackground”>@color/...</item>
<item name=”android:windowSplashScreenBrandingImage”>@drawable/...</item>
      
      



UI

Ripple

UI , Ripple . " " . Ripple





Overscroll

Android 12 (Android View) . iOS overscroll .





RenderEffect API

API, , . iOS API





//     View
view.setRenderEffect(RenderEffect.createBlurEffect(radiusX, radiusY, SHADER_TILE_MODE))
      
      



//   Window  
Window.setBackgroundBlurRadius(radius: Int)
      
      



//     
<style name="AppTheme">
    <item name="android:windowBackgroundBlurRadius">15dp</item>
</style>
      
      



Android 12 API . , iOS 14 Google API Android. :





  • Android 12+





  • , Material You









  • CheckBox, Switch RadioButton. Todo ,





<appwidget-provider
  ...
  android:targetCellWidth="3"
  android:targetCellHeight="2"
  android:maxResizeWidth="250dp"
  android:maxResizeHeight="110dp">
</appwidget-provider>
      
      



  • , UI XML





<appwidget-provider
  ...
  android:previewLayout="@layout/my_widget_preview"
  android:description="@string/my_widget_des
      
      



  • . Activity





  • API





  • Android 12





DSL Compose, Android. DSL, View, Compose .





Rounded Corner API

Rounded Corner API , .





, Google, , .





// Get the top-right rounded corner from WindowInsets.
final WindowInsets insets = getRootWindowInsets();
final RoundedCorner topRight = insets.getRoundedCorner(POSITION_TOP_RIGHT);
if (topRight == null) {
   return;
}

// Get the location of the close button in window coordinates.
int [] location = new int[2];
closeButton.getLocationInWindow(location);
final int buttonRightInWindow = location[0] + closeButton.getWidth();
final int buttonTopInWindow = location[1];

// Find the point on the quarter circle with a 45 degree angle.
final int offset = (int) (topRight.getRadius() * Math.sin(Math.toRadians(45)));
final int topBoundary = topRight.getCenter().y - offset;
final int rightBoundary = topRight.getCenter().x + offset;

// Check whether the close button exceeds the boundary.
if (buttonRightInWindow < rightBoundary && buttonTopInWindow > topBoundary) {
   return;
}

// Set the margin to avoid truncating.
int [] parentLocation = new int[2];
getLocationInWindow(parentLocation);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) closeButton.getLayoutParams();
lp.rightMargin = Math.max(buttonRightInWindow - rightBoundary, 0);
lp.topMargin = Math.max(topBoundary - buttonTopInWindow, 0);
closeButton.setLayoutParams(lp);
      
      



Rich Content Insertion

- . Google API drag-&-drop, - Rich Content Insertion. compat API OnReceiveContentListener Jetpack Core 1.5.0, Stable.





Android . :





  • MessagingStyle BigPictureStyle





  • Intent





  • - CallStyle, , .





  • , Custom View, .





""

Activity, . , BroadcastReceiver, Activity. UX . Activity - . ,





Indirect notification activity start (trampoline) from PACKAGE_NAME, \
this should be avoided for performance reasons.
      
      



AVIF

AV1, AVIF. JPG. ?





Compatible Media Transcoding

Android 12 , . Android HEVC (H.265) to AVC (H.264), HDR10 SDR. XML , AndroidManifest.





<?xml version="1.0" encoding="utf-8"?>
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
    <format android:name="HEVC" supported="true"/>
    <format android:name="HDR10" supported="false"/>
    <format android:name="HDR10Plus" supported="false"/>
</media-capabilities>
      
      



<property
    android:name="android.media.PROPERTY_MEDIA_CAPABILITIES"
    android:resource="@xml/media_capabilities" />
      
      



.





- 1080p 30 9 Pixel 4. , Pixel 4 Snapdragon 845 6 . (





Performance Class

Android 12, Performance Class. , Android. , .





if (Build.VERSION.MEDIA_PERFORMANCE_CLASS >= Build.VERSION_CODES.S) {
   // Provide the most premium experience for highest performing devices
   ...
}
else if (Build.VERSION.MEDIA_PERFORMANCE_CLASS == Build.VERSION_CODES.R)
   // Provide a  high quality experience
   ...
}
else {
   // Remove extras to keep experience functional
   ...
}
      
      



Class 12 Android 12 , , , / . , Android 13 class 12, .





  • .





  • .. 108 .





  • ,





  • Camera2 API CameraX Extentions





Android 11 . 80% . Google . Android , , , .





targetSdk=S, , .





val locationPermissionRequest = registerForActivityResult(
        ActivityResultContracts.RequestMultiplePermissions()
    ) { permissions ->
        when {
            permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> {
                //  
            }
            permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> {
                //  
            } else -> {
                //    
            }
        }
    }

// ...

locationPermissionRequest.launch(
    arrayOf(
       Manifest.permission.ACCESS_FINE_LOCATION,
       Manifest.permission.ACCESS_COARSE_LOCATION
    )
)
      
      



, , .





Nearby Bluetooth

Android Bluetooth, , . - Android 12 : BLUETOOTH_SCAN BLUETOOTH_CONNECT. BLUETOOTH_SCAN Bluetooth , BLUETOOTH_CONNECT - .





, .





Exact alarm permission

- Android . , , . alarm-, SCHEDULE_EXACT_ALARM, exact alram- AlarmManager SecurityException.



permission runtime, .



alarm- . , , , . Google Play .





//    excat alarm   <package_id> 
if (!alarmManager.canScheduleExactAlarms()) {
    startActivityForResult(
        Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, "package:<package_id>")
    )
}
      
      



Clipboard

, . , . copy-paste ? .





Foreground Service

Android 12, Android - Foreground Service , . Service ForegroundServiceStartNotAllowedException



.





:





  • High Priority Push





  • broadcast- ACTION_BOOT_COMPLETED



    , ACTION_LOCKED_BOOT_COMPLETED



    , ACTION_MY_PACKAGE_REPLACED















  • Exact alarm









API Expedited Jobs, WorkManager 2.7.0. Android 12 API JobScheduler, Android Foreground Service.





OneTimeWorkRequestBuilder<T>().apply {
    setInputData(inputData)
    setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
}.build()
      
      



Expedited job , . Expedited Job Foreground Service job JobScheduler:





  • - . job , expedited job.





  • Expedited job , Battery Saver Doze Mode.





  • expedited job , job , , . job.





Foreground Service

, ? ? Foreground Service, . Android 12 , Foreground Service, 5 . UX . , , , . c API Notification.Builder.setForegroundServiceBehavior().





Notification.Builder(context)
         .setForegroundServiceBehavior(Notification.BEHAVIOR_IMMEDIATE_DISPLAY)
         .build();
      
      



Android iOS , iOS. , status bar , - . , .





Privay Dashboard

Android 12 , . Beta.





Android 11 - . ( ), :









  • job alert





  • push , high-priority FCM





, job, alarm , .





" " , , -.





, , 200 . HIGH_SAMPLING_RATE_SENSORS, .





exported Manifest

AndroidManifest android:exported=true|false



, . false, intent-filter , true. , Slack.





targetSdk=S - exported, , Logcat .





Installation did not succeed.
The application could not be installed: INSTALL_FAILED_VERIFICATION_FAILURE
List of apks:
[0] '...app-debug.apk'
Installation failed due to: 'null'
      
      



Android Studio 2020.3.1 Arctic Fox Android Lint . , . Manifest Merger exported .





Android 12, , :





  • ART





  • Build , ().





  • App Standby bucket - Restrictive.





  • Bouncy Castle





  • Backup ( ) , .





  • PendingIntent





  • PiP





  • Web intent . Android App Links, domain





  • SameSite WebView





  • Private Compute Core - . , Smart Reply. . -.





  • . Google Play






El lanzamiento de Android 12 está previsto para este otoño, pero incluso antes de ese momento estamos quemando varias versiones Beta, que harán las delicias de las novedades mostradas en Google I / O. Recuerda que con el lanzamiento de Android 12, necesitarás adaptar tus aplicaciones a Android 11. En los comentarios, estoy esperando tus impresiones de Android 12: qué te gustó, qué no y qué más esperabas del actualización de robot verde.








All Articles