当前位置:网站首页>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 ");
}
}
}边栏推荐
- 7-23 currency conversion (using array conversion)
- Exercise 6-1 classify and count the number of characters
- Niuke: crossing the river
- 7-19 check denomination (solve binary linear equation)
- 7-7 12-24 hour system
- 洛谷P5194 [USACO05DEC]Scales S 题解
- Common commands for getting started with mongodb database
- Sendmail无法发送邮件及发送过慢解决
- JS shift operators (< <,> > and > > >)
- How to bold text in AI
猜你喜欢

Leetcode(4)——尋找兩個正序數組的中比特數

Exercise 7-6 count capital consonants

Four data flows and cases of grpc

Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块

Sword finger offer 28 Symmetric binary tree

Doris学习笔记之数据表的创建

7-8 overspeed judgment

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

Happy capital new dual currency fund nearly 4billion yuan completed its first account closing

7-9 find a small ball with a balance
随机推荐
Exercise 8-2 calculate the sum and difference of two numbers
Leetcode (4) -- find the median of two positively ordered arrays
7-14 sum integer segments (C language)
7-17 crawling worms (break exercise)
String sort
Leetcode(4)——尋找兩個正序數組的中比特數
7-7 12-24 hour system
7-28 monkeys choose King (Joseph problem)
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
Exercise 6-1 classify and count the number of characters
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
JS get DPI, PX to cm, cm to PX
Sword finger offer 28 Symmetric binary tree
7-16 find the set of integers that meet the given conditions
Canvas utility library fabric JS user manual
Fabric. JS document
Exercise 10-1 judge the three digits that meet the conditions
Raft agreement
Exercise 10-2 recursive factorial sum
中国PETG市场预测及战略研究报告(2022版)