Android 6.0 new Features

Source: Internet
Author: User

First talk about some of the new features of Android 6.0

    1. Voice Search under lock screen
    2. Fingerprint identification
    3. More complete application Rights Management
    4. Doze Power Management
    5. Now OnTap
    6. APP Link

The most important thing in the development process with us is the "more complete application Rights Management" feature, which is what matters most in this area is the runtime permissions,

Run-time permissions

On Android6.0 on the basis of the original Androidmanifest.xml declaration authority, we have added the dynamic monitoring of runtime permissions, the following permissions need to be judged at runtime

    1. Body Sensors
    2. Calendar
    3. Camera
    4. Contacts
    5. Location
    6. Microphone
    7. Phone
    8. Sms
    9. Storage space

Run-time Permission handling

The Android 6.0 system defaults to targetsdkversion less than 23 app grants all the permissions requested, so if your previous app set targetsdkversion less than 23 will not crash at run time, but this is only a temporary strategy, The user may also cancel the authorization in the settings

To declare the target SDK version, we need to declare targetsdkversion as 23 in Build.gradle

Check and Request permissions

We need to use permissions, every time we check whether the app has permissions, such as we have a download function need to write SD card, for example, we have a download function

if (Contextcompat.checkselfpermission (this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
! = packagemanager.permission_granted) {
Request Write_external_storage Permission
Activitycompat.requestpermissions (this, new String[]{manifest.permission.write_external_storage},
Write_external_storage_request_code);
}

When the permission is requested, the system will eject the request permission dialog

The Onrequestpermissionresult method is called after the user chooses to allow or deny, which is similar to Onactivityresult

@Override
public void Onrequestpermissionsresult (int requestcode, string[] permissions, int[] grantresults) {
Super.onrequestpermissionsresult (Requestcode, permissions, grantresults);
}
We then need to follow up with Requestcode and grantresults (authorization results).

Special handling of run-time permissions in fragment
    • Apply permission in fragment, do not use activitycompat.requestpermissions, use fragment Requestpermissions method directly, Otherwise it will call back to the activity's Onrequestpermissionsresult
    • If you nest fragment in fragment, the Requestpermissions method is used in the sub-fragment, and Onrequestpermissionsresult does not call back. It is recommended to use the Getparentfragment (). Requestpermissions method,

This method will call back to the Onrequestpermissionsresult in the parent fragment and add the following code to pass the callback through to the child fragment

public void Onrequestpermissionsresult (int requestcode, string[] permissions, int[] grantresults) {
Super.onrequestpermissionsresult (Requestcode, permissions, grantresults);
list<fragment> fragments = Getchildfragmentmanager (). getfragments ();
if (fragments! = null) {
for (Fragment fragment:fragments) {
if (fragment! = null) {
Fragment.onrequestpermissionsresult (Requestcode,permissions,grantresults);
}
}
}
}

Related Open source projects
      • Permissionsdispatcher
        Dynamically generated classes handle run-time permissions using annotations, and nested fragment are not currently supported.

      • Rxpermissions
        Rxjava-based runtime permission detection framework

      • Grant
        Simplifies the handling of run-time permissions and is more flexible

      • Android-runtimepermissions
        Google's official example



Android 6.0 new Features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.