Tout nouvel Android 12. Examen pour les développeurs

Salut. Je m'appelle  Kirill Rozov  et si vous êtes intéressé par le développement Android, vous avez probablement entendu parler de la  chaîne Telegram "Android Broadcast" , avec des actualités quotidiennes pour les développeurs Android, et de la  chaîne YouTube du même nom . Cet article est une transcription textuelle d'une nouvelle vidéo sur la chaîne






La conférence Google I/O a eu lieu et nous avons absolument tout appris sur la nouvelle version d'Android, et vous pouvez également essayer tout cela en Beta 1, qui peut être installé sur le Pixel over the air, ainsi que sur un certain nombre d'autres fabricants. vous permettent d'installer l'image 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






La sortie d'Android 12 est prévue pour cet automne, mais avant même cette date nous brûlons plusieurs versions Beta, ce qui ravira les nouveautés montrées sur Google I/O. N'oubliez pas qu'avec la sortie d'Android 12, vous devrez adapter vos applications à Android 11. Dans les commentaires, j'attends vos impressions sur Android 12 : ce que vous avez aimé, ce qui n'a pas mise à jour du robot vert.








All Articles