Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Android Ultra clear 6.0permission how to apply for AndPermission

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to apply for AndPermission". In the daily operation, I believe many people have doubts about how to apply for AndPermission. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to apply for Android! Next, please follow the editor to study!

Start

Preparatory work

Guide package

Compile 'com.yanzhenjie:permission:1.0.7'

Then it can be used. The thief is simple.

Use

The first step

FindViewById (R.id.selectPic) .setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {/ / detect permissions AndPermission.with (MainActivity.this) .requestCode (202) .callback (Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE) .callback (listener) .start ();}})

Explanation:

1.requestCode (): for callback use, determine where the 2.permission is applied for (): just fill in the permission to be applied for, but be sure to add 3.callback () to the AndroidManifest.xml: enter the callback object.

When you click the button, you will automatically query whether you have permission. If not, the application box will pop up. If you have permission, you will directly call back the success method inside.

Step 2 callback object

/ / permission monitoring callback private PermissionListener listener = new PermissionListener () {@ Override public void onSucceed (int requestCode, List grantedPermissions) {/ / permission application callback is successful. If (requestCode = = 202) {/ / Action after successful application}} @ Override public void onFailed (int requestCode, List deniedPermissions) {/ / callback for failed permission application. Can prompt}}

It's over. It's really simple.

At this point, the study on how to apply for AndPermission is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report