In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge points about iterative changes and adaptation methods in various versions of Android. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Android 4.4
Release ART virtual machine, provide the option to turn on.
The underlying implementation of HttpURLConnection has been changed to OkHttp.
Android 5.0
ART becomes the default virtual machine, completely replacing the Dalvik virtual machine.
The Context.bindService () method requires explicit Intent, and if an implicit intent is provided, an exception will be thrown.
Android 6.0
Add runtime permission restrictions
If your application uses dangerous permissions, such as checking and requesting permissions at run time. The checkSelfPermission () method is used to check permissions, and the requestPermissions () method is used to request permissions.
Unsupport Apache HTTP
Android version 6.0 removes support for Apache HTTP-related class libraries. To continue using Apache HTTP API, you must first advertise the following compile-time dependencies in the build.gradle file:
Android {useLibrary 'org.apache.http.legacy'}
Apache HttpClient is an open source project provided by the Apache open source organization. It is a simple HTTP client (not a browser) that can send HTTP requests and accept HTTP responses.
Android 7.0
Android 7.0introduces a new application signature scheme APK Signature Scheme v2
BadTokenException caused by Toast
On Android7.0 systems, the Android framework enforces the StrictMode API policy to prohibit the disclosure of file:// URI to your applications. If an Intent containing the file file:// URI type leaves your application, the application fails with a FileUriExposedException exception, such as calling the system camera to take photos and record videos, or trimming photos.
In fact, it restricts the sharing of files between applications. If you need to share files between applications, you need to grant temporary access to the URI you want to access. All we need to do is register FileProvider:
1) announcement FileProvider.
2) write the xml file and determine the accessible directory
/ / represents the root directory of the facility new File ("/"); / / context.getFilesDir () / / context.getCacheDir () / / Environment.getExternalStorageDirectory () / / context.getExternalFilesDirs () / / getExternalCacheDirs ()
3) use FileProvider
If (Build.VERSION.SDK_INT > = Build.VERSION_CODES.N) {Uri uri = FileProvider.getUriForFile (CameraActivity.this, "app's package name .fileProvider", photoFile);} else {Uri uri = Uri.fromFile (photoFile);} Android 8.0
Modify runtime permission error
Prior to Android 8.0, if the application requested permission at run time and was granted that permission, the system mistakenly granted the application the remaining permissions that belonged to the same permission group and registered in the inventory. For applications targeted at Android 8.0, the system will only grant the application permissions that are explicitly requested. However, once the customer grants a permission to the application, all subsequent requests for permissions in that permission group are automatically approved.
In other words, if you applied for READ_EXTERNAL_STORAGE permission before, the application will grant you WRITE_EXTERNAL_STORAGE permission for the same permission group at the same time. If Android8.0 is above, you will only be granted the READ_EXTERNAL_STORAGE permission you requested. If you need WRITE_EXTERNAL_STORAGE permission, you should apply separately, but the system will grant it immediately and will not remind you.
Notification of modification
Android 8.0 modifies a lot of notifications, such as notification channels, notification flags, notification timeouts, and background colors. One of the more important is the notification channel, which allows you to create a channel that the customer can set for each type of notification you want to display.
The advantage is that for an application, permissions can be divided into many categories, and customers can control which categories of notifications can be displayed. What the developer needs to do is to set the channel id, otherwise the notification may fail.
Private void createNotificationChannel () {if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.O) {NotificationManager notificationManager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE); / / grouping (optional) / / groupId to unique String groupId = "group_001"; NotificationChannelGroup group = new NotificationChannelGroup (groupId, "Advertising") / / create group notificationManager.createNotificationChannelGroup (group); / / channelId to unique String channelId = "channel_001"; NotificationChannel adChannel = new NotificationChannel (channelId, "promotional message", NotificationManager.IMPORTANCE_DEFAULT); / / add the meaning of channel (optional) adChannel.setDescription ("promotional message") / / add channels to the group (create a group first) adChannel.setGroup (groupId); / / create channel notificationManager.createNotificationChannel (adChannel) / / when the notification was created Mark your channel id Notification notification = new Notification.Builder (MainActivity.this, channelId) .setSmallIcon (R.mipmap.ic_launcher) .setLargeIcon (BitmapFactory.decodeResource (getResources ()) R.mipmap.ic_launcher) .setContentTitle ("A new notification") .setContentText ("this is a test message") .setAutoCancel (true) .build () NotificationManager.notify (1, notification);}}
Suspended window
A new window type (TYPE_APPLICATION_OVERLAY) must be used above Android 8.0 to display a prompt suspension window:
If (Build.VERSION.SDK_INT > = Build.VERSION_CODES.O) {mWindowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY} else {mWindowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT}
Applications from unknown sources are not allowed to be installed
Android 8.0 removes the "allow unknown sources" option, so if our App has the ability to install App (check for upgrades, etc.), it won't install properly.
Private void installAPK () {if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.O) {boolean hasInstallPermission = getPackageManager () .canRequestPackageInstalls () If (hasInstallPermission) {/ / install applications} else {/ / jump to the "install unknown applications" permission interface to guide customers to open permissions Uri selfPackageUri = Uri.parse ("package:" + this.getPackageName ()); Intent intent = new Intent (Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, selfPackageUri) StartActivityForResult (intent, 100);}} else {/ / install applications}} / / receive the result of enabling "install unknown applications" @ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super.onActivityResult (requestCode, resultCode, data); if (requestCode = = 100) {installAPK () }}
Only fullscreen opaque activities can request orientation
Only a full-screen opaque activity can set the orientation. This should be a bug, which appears in Android8.0 and is fixed in 8.1.
Our solution is to either get rid of the orientation code or get rid of transparency.
Android 9.0
Network Transport layer Security Protocol (TLS) is enabled by default in 9.0, and plaintext support is disabled by default. That is, http requests are not allowed, and https is required. The solution is to increase the network security configuration:
Remove Apache HTTP client
The support for Apache HTTP client was removed in 6.0. the library was directly removed from Android9.0. If you want to use it, you need to add configuration:
Front end service invocation
Android 9.0 requires you to request FOREGROUND_SERVICE permission to create a front-end service, otherwise the system will raise a SecurityException.
If (android.os.Build.VERSION.SDK_INT > = android.os.Build.VERSION_CODES.O) {startForegroundService (intentService);} else {startService (intentService);}
Cannot start Activity in a non-Activity environment
In 9.0, you can't start Activity directly in a non-Activity environment (such as Service,Application), otherwise it will crash and report an error. The solution is to add FLAG_ACTIVITY_NEW_TASK.
Intent intent = new Intent (this, TestActivity.class); intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity (intent); Android 10
Partition storage
Partition storage, that is, sandboxie mode, is enabled by default in Android10. Applications can only see directories specific to this application (accessed through Context.getExternalFilesDir ()) as well as specific types of media.
If you need to turn off this feature, you can configure:
Android:requestLegacyExternalStorage= "true"
Under partition storage, how to access the file:
1) Application specific directory
/ / partitioned storage space val file = File (context.filesDir, filename) / / Application specific external storage space val appSpecificExternalDir = File (context.getExternalFilesDir (), filename)
2) access public media catalog files
Val cursor = contentResolver.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "${MediaStore.MediaColumns.DATE_ADDED} desc") if (cursor! = null) {while (cursor.moveToNext ()) {val id = cursor.getLong (cursor.getColumnIndexOrThrow (MediaStore.MediaColumns._ID)) val uri = ContentUris.withAppendedId (MediaStore.Images.Media.EXTERNAL_CONTENT_URI Id) println ("image uri is $uri")} cursor.close ()}
3) SAF (Storage access Framework-Storage Access Framework)
Val intent = Intent (Intent.ACTION_OPEN_DOCUMENT) intent.addCategory (Intent.CATEGORY_OPENABLE) intent.type = "image/*" startActivityForResult (intent, 100) @ RequiresApi (Build.VERSION_CODES.KITKAT) override fun onActivityResult (requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult (requestCode, resultCode) Data) if (data = = null | | resultCode! = Activity.RESULT_OK) return if (requestCode = = 100) {val uri = data.data println ("image uri is $uri")}}
Permissions are updated again
Starting from Android10, ordinary applications are no longer allowed to request permission android.permission.READ_PHONE_STATE. Moreover, no matter whether your App has adapted to Android Q (whether the targetSdkVersion is greater than or equal to 29), you will no longer be able to obtain facility IMEI and other facility information.
If the following facilities of Android10 obtain information such as facility IMEI, you can configure the maximum sdk version:
Android 11
Partition storage enforcement
Android11 enforces partitioned storage, that is, sandboxie mode. The function is really not turned off this time, and it has been some time since Android11 came out, so let's get used to it.
Modify phone permissions
Changed two API:getLine1Number () and getMsisdn (), need to add READ_PHONE_NUMBERS permission
Do not allow yourself to set toast to display from the backend
V2 signature is required
Add 5g related API
Back-end location access is restricted again
These are all the contents of the article "iterative changes and adaptations of various versions of Android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.