当前位置:网站首页>Get permissions dynamically
Get permissions dynamically
2022-07-03 14:27:00 【Novice Xiaowang】
1. stay manifest Required permissions declared in
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />2. stay activity Dynamically apply for permission in
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"," Already have permission ");
}
}else {
Log.e("tag"," Don't apply for permission dynamically ");
}
}3.activity rewrite onRequestPermissionResult Method
@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"," Permissions obtained successfully ");
}else {
Log.e("tag"," Failed to get permission ");
}
}
}边栏推荐
- Convert string to decimal integer
- FPGA blocking assignment and non blocking assignment
- 战略、战术(和 OKR)
- Exercise 10-6 recursively find Fabonacci sequence
- Solr series of full-text search engines - basic principles of full-text search
- Why don't I have a rookie medal
- Preliminary summary of structure
- Selective sorting
- MongoDB索引
- 7-17 crawling worms (break exercise)
猜你喜欢

556. The next larger element III

Why is this error reported when modifying records in the database

基因家族特征分析 - 染色体定位分析

Fabric. JS document

MySQL multi table query subquery

7-15 calculation of PI

Exercise 10-6 recursively find Fabonacci sequence

ShowMeBug入驻腾讯会议,开启专业级技术面试时代

中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
随机推荐
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
Four data flows and cases of grpc
Statistical capital consonants
牛客网:过河卒
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
使用并行可微模拟加速策略学习
7-14 sum integer segments (C language)
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
7-18 finding the single root of polynomial by dichotomy
allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
Protobuf and grpc
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
Exercise 8-2 calculate the sum and difference of two numbers
X86 assembly language - Notes from real mode to protected mode
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
Sword finger offer 28 Symmetric binary tree
适用于XP的DDK
Preliminary summary of structure
pyQt界面制作(登录+跳转页面)