当前位置:网站首页>动态获取权限
动态获取权限
2022-07-03 14:15:00 【菜鸟xiaowang】
1.在manifest中声明需要的权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />2.在activity中动态申请权限
public void getPermission(){
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
if (ContextCompat.checkSelfPermission(this,Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},0);
}else {
Log.e("tag","已拥有权限");
}
}else {
Log.e("tag","不用动态申请权限");
}
}3.activity 重写onRequestPermissionResult 方法
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 0){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
Log.e("tag","获取权限成功");
}else {
Log.e("tag","获取权限失败");
}
}
}边栏推荐
- 7-24 reduction of the simplest fraction (rolling Division)
- Jiuyi cloud black free encryption free version source code
- Understand the application scenario and implementation mechanism of differential segment
- Thread. Sleep and timeunit SECONDS. The difference between sleep
- Accelerating strategy learning using parallel differentiable simulation
- Stop asking yourself if you are suitable for software testing
- String substitution
- Etcd cluster permission management and account password usage
- Too many files with unapproved license
- 关于回溯问题中的排列问题的思考(LeetCode46题与47题)
猜你喜欢

玖逸云黑免费无加密版本源码

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东

Exercise 6-1 classify and count the number of characters

Fabric. JS document

一文了解微分段应用场景与实现机制

7-11 calculation of residential water charges by sections

Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not

JS input number and standard digit number are compared. The problem of adding 0 to 0

The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log

Understanding of closures
随机推荐
7-14 sum integer segments (C language)
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
Raft 协议
Duet date picker (time plug-in that can manually enter the date)
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
别再问自己适不适合做软件测试了
JVM class loading
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Exercise 10-1 judge the three digits that meet the conditions
Accelerating strategy learning using parallel differentiable simulation
Solution to failure or slow downloading of electron when electron uses electron builder to package
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
7-28 monkeys choose King (Joseph problem)
Solve the problem of dormitory router campus network sharing login
Interface for querying IP home
Leetcode(4)——尋找兩個正序數組的中比特數
x86汇编语言-从实模式到保护模式 笔记
Zabbix添加Calculated items后保存页面成空白
Redis: operation command of string type data
JS first summary