当前位置:网站首页>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 ");
}
}
}边栏推荐
- Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
- 556. The next larger element III
- Exercise 6-1 classify and count the number of characters
- ConstraintLayout 的使用
- 牛客网:过河卒
- 7-6 mixed type data format input
- x86汇编语言-从实模式到保护模式 笔记
- Sendmail can't send mail and it's too slow to send. Solve it
- Jiuyi cloud black free encryption free version source code
- Exercise 8-7 string sorting
猜你喜欢

Why is this error reported when modifying records in the database

Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue

Niuke: crossing the river

Exercise 8-8 moving letters

Exercise 6-6 use a function to output an integer in reverse order

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

Exercise 10-1 calculate the sum of 1 to n using recursive functions
![[clean up the extraordinary image of Disk C]](/img/0d/331115bc5d82d6337ae975a08494b2.jpg)
[clean up the extraordinary image of Disk C]
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解
随机推荐
7-20 print 99 formula table (format output)
[clean up the extraordinary image of Disk C]
Canvas utility library fabric JS user manual
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
pyQt界面制作(登录+跳转页面)
ConstraintLayout 的使用
x86汇编语言-从实模式到保护模式 笔记
How Facebook moves instagram from AWS to its own server
Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
Sendmail无法发送邮件及发送过慢解决
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
7-9 find a small ball with a balance
中国锂电池电解液行业市场专项调研报告(2022版)
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
Exercise 10-3 recursive implementation of exponential functions
Strategy, tactics (and OKR)
修改数据库中的记录为什么报这个错
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线