Android动态权限申请
Android系统中,目前Dangerous级别的权限都需要动态申请。步骤如下;
1、AndroidManfiest.xml中申明需要的动态权限
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plbear.yyj.dangerouspermission">
<!-- 声明权限 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
2、代码中检查权限、申请权限
如下方法执行之后,会弹出提示框,提示要申请该权限
fun onClick_requestPermission(v: View) {
if (ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 0);
}
}
3、获取结果
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
var i = 0;
while (i < permissions.size) {
Log.e(TAG, "permission:" + permissions[i] + " grantResult:" + grantResults[i])
i++
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
转载请注明链接:http://www.cnblogs.com/yanyojun/p/8013003.html
本文所有代码已放置到GitHub:https://github.com/YanYoJun/DangerousPermission/
Android动态权限申请的更多相关文章
- Android 动态权限申请
package com.dragon.android.permissionrequest; import android.Manifest; import android.content.Dialog ...
- 【Unity游戏开发】Android6.0以上的动态权限申请问题
一.引子 最近公司的游戏在做安全性测试,期间也暴露出了不少安全上的问题.虽然我们今天要说的权限申请和安全性相关不大,但是也会影响到游戏的使用体验等,所以本篇博客中马三就想和大家谈谈Android6.0 ...
- Android 6.0动态权限申请
转载(Android 6.0 动态权限申请简单简洁优雅的处理方式): https://blog.csdn.net/lin_dianwei/article/details/79025324
- Android6.0动态权限申请
goggle在Android6.0要求部分权限需要动态申请,直接下载AndroidManifest.xml中无效 6.0权限的基本知识,以下是需要单独申请的权限,共分为9组, 每组只要有一个权限申请成 ...
- Android6.0动态权限申请步骤以及需要注意的一些坑
因为工作需要,简单研究了一下Android6.0权限申请,在Google提供的sample的基础上,写了一个简单的demo.算是自己的笔记吧,可能会比较混乱,主要是方便以后查看.后期有别的问题,随时更 ...
- android动态权限获取
android动态权限获取 Android6.0采用新的权限模型,只有在需要权限的时候,才告知用户是否授权,是在runtime时候授权,而不是在原来安装的时候 ,同时默认情况下每次在运行时打开页面时候 ...
- DELPHI安卓动态权限申请
DELPHI安卓动态权限申请 安卓8.0以前的版本,只需要给静态权限就可以了,但安卓8.0及以后的版本,还需要运行期用代码动态申请权限. 下面以<蓝牙权限>为例,其他权限类似. Delph ...
- checkSelfPermission 找不到 Android 动态权限问题
checkSelfPermission 找不到 Android 动态权限问题 最近写了一个Demo,以前好好地.后来手机更新了新系统以后,不能用总是闪退.而且我的小伙伴的是android 7.0系统 ...
- Android 6.0 动态权限申请注意事项
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/uana_777/article/details/54136255 Part One 权限区分 And ...
随机推荐
- python各进制、字节串间的转换
>>> i = 13 >>> bin(i) '0b1101' >>> oct(i) '0o15' >>> hex(i) '0xd ...
- Highcharts报表——让你的网页上图表画的飞起
Highcharts是一款纯javascript编写的图表库,能够很简单便捷的在Web网站或Web应用中添加交互性的图表,Highcharts目前支持直线图.曲线图.面积图.柱状图.饼图.散点图等多达 ...
- 设计模式-(12)迭代器模式 (swift版)
一,概念 迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常用的设计模式.这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示.迭代器模式属于行为型 ...
- method.invoke()使用
public Object invoke(Object obj, Object... args) throws IllegalAccessException, IllegalArgumentExcep ...
- spring boot 使用过滤器
//启动类添加注解@ServletComponentScan package com.baiwang.invoice.utils; import java.io.IOException; import ...
- u-boot支持LCD显示(基于TQ2440)【转】
本文转载自:http://www.cnblogs.com/pengdonglin137/p/4633877.html u-boot支持LCD显示(基于TQ2440) 阅读目录(Content) 平 ...
- 一步一步学Silverlight 2系列(4):鼠标事件处理
一步一步学Silverlight 2系列(4):鼠标事件处理 概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言V ...
- HttpWebRequest以及HttpWebResponse
上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...
- Remove '@override' annotation解决办法
最近刚刚配置了新机器,将原来的代码放在eclipse上执行,总会出现Remove '@override' annotation,如果要一个个手动删除相当麻烦,最后在网上找了一下原因原来是编译器版本的问 ...
- Python3中 对local和nonlocal 关键字的改善认识(新手向)
nonlocal关键字用来在函数或其他作用域中使用外层(非全局)变量. nonlocal用于声明,修改嵌套作用域(enclosing 作用域,外层非全局作用域)中的变量,如下实例: #!/usr/bi ...