安卓权限_安卓权限设置 - CSDN
精华内容
参与话题
  • 安卓权限大全

    千次阅读 2018-06-07 17:28:02
    转载:https://www.cnblogs.com/classic/archive/2011/06/20/2085055.html访问登记属性android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限获取错略位置android.permission....

    转载:https://www.cnblogs.com/classic/archive/2011/06/20/2085055.html

    访问登记属性android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限
    获取错略位置android.permission.ACCESS_COARSE_LOCATION,通过WiFi或移动基站的方式获取用户错略的经纬度信息,定位精度大概误差在30~1500米
    获取精确位置android.permission.ACCESS_FINE_LOCATION,通过GPS芯片接收卫星的定位信息,定位精度达10米以内
    访问定位额外命令android.permission.ACCESS_LOCATION_EXTRA_COMMANDS,允许程序访问额外的定位提供者指令
    获取模拟定位信息android.permission.ACCESS_MOCK_LOCATION,获取模拟定位信息,一般用于帮助开发者调试应用
    获取网络状态android.permission.ACCESS_NETWORK_STATE,获取网络信息状态,如当前的网络连接是否有效
    访问Surface Flingerandroid.permission.ACCESS_SURFACE_FLINGER,Android平台上底层的图形显示支持,一般用于游戏或照相机预览界面和底层模式的屏幕截图
    获取WiFi状态android.permission.ACCESS_WIFI_STATE,获取当前WiFi接入的状态以及WLAN热点的信息
    账户管理android.permission.ACCOUNT_MANAGER,获取账户验证信息,主要为GMail账户信息,只有系统级进程才能访问的权限
    验证账户android.permission.AUTHENTICATE_ACCOUNTS,允许一个程序通过账户验证方式访问账户管理ACCOUNT_MANAGER相关信息
    电量统计android.permission.BATTERY_STATS,获取电池电量统计信息
    绑定小插件android.permission.BIND_APPWIDGET,允许一个程序告诉appWidget服务需要访问小插件的数据库,只有非常少的应用才用到此权限
    绑定设备管理android.permission.BIND_DEVICE_ADMIN,请求系统管理员接收者receiver,只有系统才能使用
    绑定输入法android.permission.BIND_INPUT_METHOD ,请求InputMethodService服务,只有系统才能使用
    绑定RemoteViewandroid.permission.BIND_REMOTEVIEWS,必须通过RemoteViewsService服务来请求,只有系统才能用
    绑定壁纸android.permission.BIND_WALLPAPER,必须通过WallpaperService服务来请求,只有系统才能用
    使用蓝牙android.permission.BLUETOOTH,允许程序连接配对过的蓝牙设备
    蓝牙管理android.permission.BLUETOOTH_ADMIN,允许程序进行发现和配对新的蓝牙设备
    变成砖头android.permission.BRICK,能够禁用手机,非常危险,顾名思义就是让手机变成砖头
    应用删除时广播android.permission.BROADCAST_PACKAGE_REMOVED,当一个应用在删除时触发一个广播
    收到短信时广播android.permission.BROADCAST_SMS,当收到短信时触发一个广播
    连续广播android.permission.BROADCAST_STICKY,允许一个程序收到广播后快速收到下一个广播
    WAP PUSH广播android.permission.BROADCAST_WAP_PUSH,WAP PUSH服务收到后触发一个广播
    拨打电话android.permission.CALL_PHONE,允许程序从非系统拨号器里输入电话号码
    通话权限android.permission.CALL_PRIVILEGED,允许程序拨打电话,替换系统的拨号器界面
    拍照权限android.permission.CAMERA,允许访问摄像头进行拍照
    改变组件状态android.permission.CHANGE_COMPONENT_ENABLED_STATE,改变组件是否启用状态
    改变配置android.permission.CHANGE_CONFIGURATION,允许当前应用改变配置,如定位
    改变网络状态android.permission.CHANGE_NETWORK_STATE,改变网络状态如是否能联网
    改变WiFi多播状态android.permission.CHANGE_WIFI_MULTICAST_STATE,改变WiFi多播状态
    改变WiFi状态android.permission.CHANGE_WIFI_STATE,改变WiFi状态
    清除应用缓存android.permission.CLEAR_APP_CACHE,清除应用缓存
    清除用户数据android.permission.CLEAR_APP_USER_DATA,清除应用的用户数据
    底层访问权限android.permission.CWJ_GROUP,允许CWJ账户组访问底层信息
    手机优化大师扩展权限android.permission.CELL_PHONE_MASTER_EX,手机优化大师扩展权限
    控制定位更新android.permission.CONTROL_LOCATION_UPDATES,允许获得移动网络定位信息改变
    删除缓存文件android.permission.DELETE_CACHE_FILES,允许应用删除缓存文件
    删除应用android.permission.DELETE_PACKAGES,允许程序删除应用
    电源管理android.permission.DEVICE_POWER,允许访问底层电源管理
    应用诊断android.permission.DIAGNOSTIC,允许程序到RW到诊断资源
    禁用键盘锁android.permission.DISABLE_KEYGUARD,允许程序禁用键盘锁
    转存系统信息android.permission.DUMP,允许程序获取系统dump信息从系统服务
    状态栏控制android.permission.EXPAND_STATUS_BAR,允许程序扩展或收缩状态栏
    工厂测试模式android.permission.FACTORY_TEST,允许程序运行工厂测试模式
    使用闪光灯android.permission.FLASHLIGHT,允许访问闪光灯
    强制后退android.permission.FORCE_BACK,允许程序强制使用back后退按键,无论Activity是否在顶层
    访问账户Gmail列表android.permission.GET_ACCOUNTS,访问GMail账户列表
    获取应用大小android.permission.GET_PACKAGE_SIZE,获取应用的文件大小
    获取任务信息android.permission.GET_TASKS,允许程序获取当前或最近运行的应用
    允许全局搜索android.permission.GLOBAL_SEARCH,允许程序使用全局搜索功能
    硬件测试android.permission.HARDWARE_TEST,访问硬件辅助设备,用于硬件测试
    注射事件android.permission.INJECT_EVENTS,允许访问本程序的底层事件,获取按键、轨迹球的事件流
    安装定位提供android.permission.INSTALL_LOCATION_PROVIDER,安装定位提供
    安装应用程序android.permission.INSTALL_PACKAGES,允许程序安装应用
    内部系统窗口android.permission.INTERNAL_SYSTEM_WINDOW,允许程序打开内部窗口,不对第三方应用程序开放此权限
    访问网络android.permission.INTERNET,访问网络连接,可能产生GPRS流量
    结束后台进程android.permission.KILL_BACKGROUND_PROCESSES,允许程序调用killBackgroundProcesses(String).方法结束后台进程
    管理账户android.permission.MANAGE_ACCOUNTS,允许程序管理AccountManager中的账户列表
    管理程序引用android.permission.MANAGE_APP_TOKENS,管理创建、摧毁、Z轴顺序,仅用于系统
    高级权限android.permission.MTWEAK_USER,允许mTweak用户访问高级系统权限
    社区权限android.permission.MTWEAK_FORUM,允许使用mTweak社区权限
    软格式化android.permission.MASTER_CLEAR,允许程序执行软格式化,删除系统配置信息
    修改声音设置android.permission.MODIFY_AUDIO_SETTINGS,修改声音设置信息
    修改电话状态android.permission.MODIFY_PHONE_STATE,修改电话状态,如飞行模式,但不包含替换系统拨号器界面
    格式化文件系统android.permission.MOUNT_FORMAT_FILESYSTEMS,格式化可移动文件系统,比如格式化清空SD卡
    挂载文件系统android.permission.MOUNT_UNMOUNT_FILESYSTEMS,挂载、反挂载外部文件系统
    允许NFC通讯android.permission.NFC,允许程序执行NFC近距离通讯操作,用于移动支持
    永久Activityandroid.permission.PERSISTENT_ACTIVITY,创建一个永久的Activity,该功能标记为将来将被移除
    处理拨出电话android.permission.PROCESS_OUTGOING_CALLS,允许程序监视,修改或放弃播出电话
    读取日程提醒android.permission.READ_CALENDAR,允许程序读取用户的日程信息
    读取联系人android.permission.READ_CONTACTS,允许应用访问联系人通讯录信息
    屏幕截图android.permission.READ_FRAME_BUFFER,读取帧缓存用于屏幕截图
    读取收藏夹和历史记录com.android.browser.permission.READ_HISTORY_BOOKMARKS,读取浏览器收藏夹和历史记录
    读取输入状态android.permission.READ_INPUT_STATE,读取当前键的输入状态,仅用于系统
    读取系统日志android.permission.READ_LOGS,读取系统底层日志
    读取电话状态android.permission.READ_PHONE_STATE,访问电话状态
    读取短信内容android.permission.READ_SMS,读取短信内容
    读取同步设置android.permission.READ_SYNC_SETTINGS,读取同步设置,读取Google在线同步设置
    读取同步状态android.permission.READ_SYNC_STATS,读取同步状态,获得Google在线同步状态
    重启设备android.permission.REBOOT,允许程序重新启动设备
    开机自动允许android.permission.RECEIVE_BOOT_COMPLETED,允许程序开机自动运行
    接收彩信android.permission.RECEIVE_MMS,接收彩信
    接收短信android.permission.RECEIVE_SMS,接收短信
    接收Wap Pushandroid.permission.RECEIVE_WAP_PUSH,接收WAP PUSH信息
    录音android.permission.RECORD_AUDIO,录制声音通过手机或耳机的麦克
    排序系统任务android.permission.REORDER_TASKS,重新排序系统Z轴运行中的任务
    结束系统任务android.permission.RESTART_PACKAGES,结束任务通过restartPackage(String)方法,该方式将在外来放弃
    发送短信android.permission.SEND_SMS,发送短信
    设置Activity观察其android.permission.SET_ACTIVITY_WATCHER,设置Activity观察器一般用于monkey测试
    设置闹铃提醒com.android.alarm.permission.SET_ALARM,设置闹铃提醒
    设置总是退出android.permission.SET_ALWAYS_FINISH,设置程序在后台是否总是退出
    设置动画缩放android.permission.SET_ANIMATION_SCALE,设置全局动画缩放
    设置调试程序android.permission.SET_DEBUG_APP,设置调试程序,一般用于开发
    设置屏幕方向android.permission.SET_ORIENTATION,设置屏幕方向为横屏或标准方式显示,不用于普通应用
    设置应用参数android.permission.SET_PREFERRED_APPLICATIONS,设置应用的参数,已不再工作具体查看addPackageToPreferred(String) 介绍
    设置进程限制android.permission.SET_PROCESS_LIMIT,允许程序设置最大的进程数量的限制
    设置系统时间android.permission.SET_TIME,设置系统时间
    设置系统时区android.permission.SET_TIME_ZONE,设置系统时区
    设置桌面壁纸android.permission.SET_WALLPAPER,设置桌面壁纸
    设置壁纸建议android.permission.SET_WALLPAPER_HINTS,设置壁纸建议
    发送永久进程信号android.permission.SIGNAL_PERSISTENT_PROCESSES,发送一个永久的进程信号
    状态栏控制android.permission.STATUS_BAR,允许程序打开、关闭、禁用状态栏
    访问订阅内容android.permission.SUBSCRIBED_FEEDS_READ,访问订阅信息的数据库
    写入订阅内容android.permission.SUBSCRIBED_FEEDS_WRITE,写入或修改订阅内容的数据库
    显示系统窗口android.permission.SYSTEM_ALERT_WINDOW,显示系统窗口
    更新设备状态android.permission.UPDATE_DEVICE_STATS,更新设备状态
    使用证书android.permission.USE_CREDENTIALS,允许程序请求验证从AccountManager
    使用SIP视频android.permission.USE_SIP,允许程序使用SIP视频服务
    使用振动android.permission.VIBRATE,允许振动
    唤醒锁定android.permission.WAKE_LOCK,允许程序在手机屏幕关闭后后台进程仍然运行
    写入GPRS接入点设置android.permission.WRITE_APN_SETTINGS,写入网络GPRS接入点设置
    写入日程提醒android.permission.WRITE_CALENDAR,写入日程,但不可读取
    写入联系人android.permission.WRITE_CONTACTS,写入联系人,但不可读取
    写入外部存储android.permission.WRITE_EXTERNAL_STORAGE,允许程序写入外部存储,如SD卡上写文件
    写入Google地图数据android.permission.WRITE_GSERVICES,允许程序写入Google Map服务数据
    写入收藏夹和历史记录com.android.browser.permission.WRITE_HISTORY_BOOKMARKS,写入浏览器历史记录或收藏夹,但不可读取
    读写系统敏感设置android.permission.WRITE_SECURE_SETTINGS,允许程序读写系统安全敏感的设置项
    读写系统设置android.permission.WRITE_SETTINGS,允许读写系统设置项
    编写短信android.permission.WRITE_SMS,允许编写短信
    写入在线同步设置android.permission.WRITE_SYNC_SETTINGS,写入Google在线同步设置
    展开全文
  • 安卓动态权限的获取

    千次阅读 2019-06-20 12:32:16
    终于找出一个时间,来整理一下,安卓动态权限的获取。仅以此文,记录一下。 首先,拍照权限是比较特殊的,一会儿会一次为例。 首先第一步,在配置文件中,添加所需的文件。 第二步:此处是针对于 拍照权限。 ...

    终于找出一个时间,来整理一下,安卓动态权限的获取。仅以此文,记录一下。

    首先,拍照权限是比较特殊的,一会儿会一次为例。

    首先第一步,在配置文件中,添加所需的文件。

    第二步:此处是针对于 拍照权限。

    其中,@xml/file_path 为自己创建的文件。

     第三步:就是权限的动态获取

    在需要请求权限的地方才进行 权限的请求

     1.检查是否包含所需权限

    2.如果没有包含权限,请求开启权限或者去往设置权限页面

    3.包含权限,就直接进行拍照等,相关操作。

    代码如下:

    private static final String[] permissions = {
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.CAPTURE_VIDEO_OUTPUT,
            Manifest.permission.CAMERA,
            Manifest.permission.RECORD_AUDIO
    };

    申请权限的权限组

    /**
     * 检查权限有没有获取
     */
    public void requestPerssionAtFirst(HomeView.HomeGetPermission listener, int resId) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // 检查该权限是否已经获取
            int i = ContextCompat.checkSelfPermission(screen, permissions[0]);
            // 权限是否已经 授权 GRANTED---授权  DINIED---拒绝
            if (i != PackageManager.PERMISSION_GRANTED) {
                // 如果没有授予该权限,就去提示用户请求
                showDialogTipUserRequestPermission();
            } else {//获取权限之后 要进行的操作
    
                listener.havePermission(resId);//有权限之后的操作
    
            }
        }
    }
    
    // 提示用户该请求权限的弹出框
    private void showDialogTipUserRequestPermission() {
        new AlertDialog.Builder(screen)
                .setTitle("相机权限、读写权限")
                .setMessage("由于需要摄像,需要开启相机权限\n" +
                        "存储文件,需要开启读写权限\n" +
                        "否则无法正常使用")
                .setPositiveButton("立即开启", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startRequestPermission();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        App.showToast("请允许权限开启");
                        screen.finish();
                    }
                }).setCancelable(false).show();
    }
    
    // 开始提交请求权限
    private void startRequestPermission() {
        ActivityCompat.requestPermissions(screen, permissions, 321);
    }
    
    
    // 提示用户去应用设置界面手动开启权限
    public void showDialogTipUserGoToAppSettting() {
        dialog = new AlertDialog.Builder(screen)
                .setTitle("权限不可用")
                .setMessage("请在-应用设置-权限-中,手动开启权限")
                .setPositiveButton("去开启", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 跳转到应用设置界面
                        goToAppSetting();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        App.showToast("请允许权限开启");
                        screen.finish();
                    }
                }).setCancelable(false).show();
    }
    
    // 跳转到当前应用的设置界面
    private void goToAppSetting() {
        Intent intent = new Intent();
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", App.getContext().getPackageName(), null);
        intent.setData(uri);
        screen.startActivityForResult(intent, 123);
    }
    

    暴露一个接口,根据实际需求,设置参数,动态设置。可以设置成控件的ID

     

    在需要申请权限的页面,代码如下:

    实现权限以获取的接口

     回调方法中,可以根据控件的ID,进行判断,不同的控件点击事件,调用不同的方法,视情况而定。

     

     

    展开全文
  • Android申请权限

    万次阅读 2018-04-27 15:45:41
    Android申请权限 Android 6.0系统加入了危险权限管理,在使用一些涉及到用户隐私方面的操作时,需要获取用户的授权才能使用,如通讯录、打电话、短信、相机、定位、录音、存储等隐私权限。获取用户授权权限,我们...

    Android申请权限

    Android 6.0系统加入了危险权限管理,在使用一些涉及到用户隐私方面的操作时,需要获取用户的授权才能使用,如通讯录、打电话、短信、相机、定位、录音、存储等隐私权限。获取用户授权权限,我们提倡动态申请权限,用到的时候才去向用户申请,例如点击扫一扫,这时我们申请相机权限,用户也明白,自然就授权了。即使用户没有授权,也仅仅影响此模块不能使用正常功能,并不影响其他模块。千万不能,在应用打开时的启屏页,一股脑把应用所有地方用到的权限都申请,不给还不能用,简直是流氓行为!

    本文大纲:

    • Android权限
    • 申请权限流程
      • 检查是否已被授权危险权限
      • 提示或解释接下来的操作需要危险权限
      • 申请权限
    • 申请权限引起的生命周期变化
    • 申请权限封装
    • 总结

    一、Android权限

    Android中的权限分为系统权限和应用自定义权限,系统权限又分为正常权限和危险权限。使用系统权限需要在manifest文件中注册权限,若是危险权限,还需要在使用时动态申请。

    terminal中使用这个命令可以列出调试手机的所有权限,包含应用自定义的权限:

    adb shell pm list permissions

    正常权限(Normal Permissions):

    ACCESS_LOCATION_EXTRA_COMMANDS
    ACCESS_NETWORK_STATE
    ACCESS_NOTIFICATION_POLICY
    ACCESS_WIFI_STATE
    BLUETOOTH
    BLUETOOTH_ADMIN
    BROADCAST_STICKY
    CHANGE_NETWORK_STATE
    CHANGE_WIFI_MULTICAST_STATE
    CHANGE_WIFI_STATE
    DISABLE_KEYGUARD
    EXPAND_STATUS_BAR
    GET_PACKAGE_SIZE
    INSTALL_SHORTCUT
    INTERNET
    KILL_BACKGROUND_PROCESSES
    MODIFY_AUDIO_SETTINGS
    NFC
    READ_SYNC_SETTINGS
    READ_SYNC_STATS
    RECEIVE_BOOT_COMPLETED
    REORDER_TASKS
    REQUEST_INSTALL_PACKAGES
    SET_ALARM
    SET_TIME_ZONE
    SET_WALLPAPER
    SET_WALLPAPER_HINTS
    TRANSMIT_IR
    UNINSTALL_SHORTCUT
    USE_FINGERPRINT
    VIBRATE
    WAKE_LOCK
    WRITE_SYNC_SETTINGS
    

    危险权限(Dangerous Permissions):

    group:android.permission-group.CONTACTS
      permission:android.permission.WRITE_CONTACTS
      permission:android.permission.GET_ACCOUNTS
      permission:android.permission.READ_CONTACTS
    
    group:android.permission-group.PHONE
      permission:android.permission.READ_CALL_LOG
      permission:android.permission.READ_PHONE_STATE
      permission:android.permission.CALL_PHONE
      permission:android.permission.WRITE_CALL_LOG
      permission:android.permission.USE_SIP
      permission:android.permission.PROCESS_OUTGOING_CALLS
      permission:com.android.voicemail.permission.ADD_VOICEMAIL
    
    group:android.permission-group.CALENDAR
      permission:android.permission.READ_CALENDAR
      permission:android.permission.WRITE_CALENDAR
    
    group:android.permission-group.CAMERA
      permission:android.permission.CAMERA
    
    group:android.permission-group.SENSORS
      permission:android.permission.BODY_SENSORS
    
    group:android.permission-group.LOCATION
      permission:android.permission.ACCESS_FINE_LOCATION
      permission:android.permission.ACCESS_COARSE_LOCATION
    
    group:android.permission-group.STORAGE
      permission:android.permission.READ_EXTERNAL_STORAGE
      permission:android.permission.WRITE_EXTERNAL_STORAGE
    
    group:android.permission-group.MICROPHONE
      permission:android.permission.RECORD_AUDIO
    
    group:android.permission-group.SMS
      permission:android.permission.READ_SMS
      permission:android.permission.RECEIVE_WAP_PUSH
      permission:android.permission.RECEIVE_MMS
      permission:android.permission.RECEIVE_SMS
      permission:android.permission.SEND_SMS
      permission:android.permission.READ_CELL_BROADCASTS
    

    二、申请权限流程

    动态申请权限的流程:

    这里写图片描述

    1、检查是否已被授权危险权限

    /**
     * 检查是否已被授权危险权限
     * @param permissions
     * @return
     */
    public boolean checkDangerousPermissions(Activity ac, String[] permissions) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return true;
        }
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED ||
                    ActivityCompat.shouldShowRequestPermissionRationale(ac, permission)) {
                return false;
            }
        }
        return true;
    }
    

    Android 6.0以下,在AndroidManifest.xml文件中注册权限即可。
    Android 6.0及其以后,既要在AndroidManifest.xml文件中注册,又要动态申请危险权限。

    2、提示或解释接下来的操作需要危险权限

    在申请危险权限时,有些用户觉得涉及到了他的隐私内容,可能不会授权。在用户拒绝后,再提示授权危险权限的必要性,就为时已晚,用户需要去设置里打开(拒绝时设置不在提醒)。如若我们在申请权限前,就有一个温馨提示,告诉用户危险权限的必要性,用户理解后更容易授权。

    饿了么的权限申请过程:

    这里写图片描述

    3、申请权限

    在activity中申请权限,权限授权结果会回调在acitvity中:

    //acitivty中申请权限
    ActivityCompat.requestPermissions(activity, permissions, requestCode);
    
    //activity权限授权结果回调
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    

    下面我们看ActivityCompat.requestPermissions这个方法:

    public static void requestPermissions(final @NonNull Activity activity,
            final @NonNull String[] permissions, final @IntRange(from = 0) int requestCode) {
        if (Build.VERSION.SDK_INT >= 23) {
            if (activity instanceof RequestPermissionsRequestCodeValidator) {
                ((RequestPermissionsRequestCodeValidator) activity)
                        .validateRequestPermissionsRequestCode(requestCode);
            }
            activity.requestPermissions(permissions, requestCode);
        } else if (activity instanceof OnRequestPermissionsResultCallback) {
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    final int[] grantResults = new int[permissions.length];
    
                    PackageManager packageManager = activity.getPackageManager();
                    String packageName = activity.getPackageName();
    
                    final int permissionCount = permissions.length;
                    for (int i = 0; i < permissionCount; i++) {
                        grantResults[i] = packageManager.checkPermission(
                                permissions[i], packageName);
                    }
    
                    ((OnRequestPermissionsResultCallback) activity).onRequestPermissionsResult(
                            requestCode, permissions, grantResults);
                }
            });
        }
    }
    
    • 系统版本大于等于Android 6.0,请求权限时,先校验requestCode是否有效,再去调用activity的requestPermissions申请权限。

    • 系统小于Android 6.0,请求权限时,在主线程检查AndroidManifest.xml文件中是否注册权限,并将结果回调。

    我们把activity.requestPermissions()放在这,等会再看他。查源码我们知道FragmentActivity实现了这两个接口:

    ActivityCompat.OnRequestPermissionsResultCallback
    ActivityCompat.RequestPermissionsRequestCodeValidator

    public class FragmentActivity extends BaseFragmentActivityApi16 implements
            ActivityCompat.OnRequestPermissionsResultCallback,
            ActivityCompat.RequestPermissionsRequestCodeValidator {
    
       .......省略
    
    
        @Override
        public final void validateRequestPermissionsRequestCode(int requestCode) {
            // We use 16 bits of the request code to encode the fragment id when
            // requesting permissions from a fragment. Hence, requestPermissions()
            // should validate the code against that but we cannot override it as
            // we can not then call super and also the ActivityCompat would call
            // back to this override. To handle this we use dependency inversion
            // where we are the validator of request codes when requesting
            // permissions in ActivityCompat.
            if (!mRequestedPermissionsFromFragment
                    && requestCode != -1) {
                checkForValidRequestCode(requestCode);
            }
        }
    
        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                @NonNull int[] grantResults) {
            int index = (requestCode >> 16) & 0xffff;
            if (index != 0) {
                index--;
    
                String who = mPendingFragmentActivityResults.get(index);
                mPendingFragmentActivityResults.remove(index);
                if (who == null) {
                    Log.w(TAG, "Activity result delivered for unknown Fragment.");
                    return;
                }
                Fragment frag = mFragments.findFragmentByWho(who);
                if (frag == null) {
                    Log.w(TAG, "Activity result no fragment exists for who: " + who);
                } else {
                    frag.onRequestPermissionsResult(requestCode & 0xffff, permissions, grantResults);
                }
            }
        }  
        .......省略
    }
    

    BaseFragmentActivityApi14.class中:

    /**
     * Checks whether the given request code is a valid code by masking it with 0xffff0000. Throws
     * an {@link IllegalArgumentException} if the code is not valid.
     */
    static void checkForValidRequestCode(int requestCode) {
        if ((requestCode & 0xffff0000) != 0) {
            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
        }
    }
    

    requestCode是int数据类型,4个字节,按2进制是32位数据,从上面可以知道它的取值是有范围的,只用到了低16位,0x00000000 ~ 0x0000ffff0 ~ 65535,那系统保留高16位有什么用呢?我们看到上面FragmentActivityonRequestPermissionsResult中,先查找是否是fragment请求的权限,然后直接&0xffff,也就是取requestCode得低16位,并回调权限结果在fragment中。

    接下来我们看在fragment中请求权限:

    //fragment中申请权限
    framgent.requestPermissions(permissions, requestCode);
    
    //fragment权限授权结果回调
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    

    framgentrequestPermissions方法:

    public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
        if (mHost == null) {
            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
        }
        mHost.onRequestPermissionsFromFragment(this, permissions, requestCode);
    }
    

    我们mHost即是fragment的宿主activity,在 FragmentActivityonRequestPermissionsFromFragment

        @Override
        public void onRequestPermissionsFromFragment(@NonNull Fragment fragment,
                @NonNull String[] permissions, int requestCode) {
            FragmentActivity.this.requestPermissionsFromFragment(fragment, permissions,
                    requestCode);
        }
    
    
        /**
         * Called by Fragment.requestPermissions() to implement its behavior.
         */
        void requestPermissionsFromFragment(Fragment fragment, String[] permissions,
                int requestCode) {
            if (requestCode == -1) {
                ActivityCompat.requestPermissions(this, permissions, requestCode);
                return;
            }
            checkForValidRequestCode(requestCode);
            try {
                mRequestedPermissionsFromFragment = true;
                int requestIndex = allocateRequestIndex(fragment);
                ActivityCompat.requestPermissions(this, permissions,
                        ((requestIndex + 1) << 16) + (requestCode & 0xffff));
            } finally {
                mRequestedPermissionsFromFragment = false;
            }
        }
    
    • requestCode = -1时,直接调用ActivityCompat.requestPermissions
    • requestCode != -1时,先校验requestCode是否有效,即 0 ~ 65535。然后获取一个分配请求索引(范围0 ~ 0xffff - 10 ~ 65534),索引加1之后左移16位,在和requestCode的低16组成新的requestCode
      0xaaaabbbb:高16位aaaa为索引加1之后左移16位,低16位bbbbfragmentrequestCode, 这就和之前在fragment中回调权限结果时requestCode一致了。

    最后都会调用ActivityCompat.requestPermissions,就回到了前面,既而activity.requestPermissions(),再来看AcitvityrequestPermissions

    public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
        if (requestCode < 0) {
            throw new IllegalArgumentException("requestCode should be >= 0");
        }
        if (mHasCurrentPermissionsRequest) {
            Log.w(TAG, "Can reqeust only one set of permissions at a time");
            // Dispatch the callback with empty arrays which means a cancellation.
            onRequestPermissionsResult(requestCode, new String[0], new int[0]);
            return;
        }
        Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
        startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
        mHasCurrentPermissionsRequest = true;
    }
    
    • 通过startActivityForResult打开系统授权权限界面,注意字符串常量REQUEST_PERMISSIONS_WHO_PREFIX
    • 不可短时间内重复执行同一请求权限代码,否则第一次之后的直接给定默认值结果,若结果grantResults会错误影响授权。

    然而在 ActivityonRequestPermissionsFromFragment中,这与FragmentActivity中的不一样

        @Override
        public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions,
                int requestCode) {
            String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho;
            Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
            startActivityForResult(who, intent, requestCode, null);
        }
    

    最终会通过startActivityForResult打开系统权限授权界面。注意这个who,系统权限授权界面回调结果时,就是根据这个who把结果分配给指定的fragment,即结果回调到fragment的onRequestPermissionsResult。 fragment请求权限时,requestCode取值范围没有限制.

    既然是通过startActivityForResult打开系统授权权限界面,那我们能在activity的onActivityResult(int requestCode, int resultCode, Intent data)中拿到授权结果吗?答案是不能,让我们一起来看为什么。当结果回传来时,都会调用ActivitydispatchActivityResult分配结果。

    void dispatchActivityResult(String who, int requestCode,
        int resultCode, Intent data) {
        if (false) Log.v(
            TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode
            + ", resCode=" + resultCode + ", data=" + data);
        mFragments.noteStateNotSaved();
        if (who == null) {
            onActivityResult(requestCode, resultCode, data);
        } else if (who.startsWith(REQUEST_PERMISSIONS_WHO_PREFIX)) {
            who = who.substring(REQUEST_PERMISSIONS_WHO_PREFIX.length());
            if (TextUtils.isEmpty(who)) {
                dispatchRequestPermissionsResult(requestCode, data);
            } else {
                Fragment frag = mFragments.findFragmentByWho(who);
                if (frag != null) {
                    dispatchRequestPermissionsResultToFragment(requestCode, data, frag);
                }
            }
        } else if (who.startsWith("@android:view:")) {
            ArrayList<ViewRootImpl> views = WindowManagerGlobal.getInstance().getRootViews(
                    getActivityToken());
            for (ViewRootImpl viewRoot : views) {
                if (viewRoot.getView() != null
                        && viewRoot.getView().dispatchActivityResult(
                                who, requestCode, resultCode, data)) {
                    return;
                }
            }
        } else if (who.startsWith(AUTO_FILL_AUTH_WHO_PREFIX)) {
            Intent resultData = (resultCode == Activity.RESULT_OK) ? data : null;
            getAutofillManager().onAuthenticationResult(requestCode, resultData);
        } else {
            Fragment frag = mFragments.findFragmentByWho(who);
            if (frag != null) {
                frag.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
    

    这时字符串常量REQUEST_PERMISSIONS_WHO_PREFIX就派上用场了。如果who不为空,说明activity是Activity,不是FragmentActivity,直接结果回调在fragment中。如果为空,actvity不一定为FragmentActivity,结果直接进入Activity的
    dispatchRequestPermissionsResult(requestCode, data);

    private void dispatchRequestPermissionsResult(int requestCode, Intent data) {
        mHasCurrentPermissionsRequest = false;
        // If the package installer crashed we may have not data - best effort.
        String[] permissions = (data != null) ? data.getStringArrayExtra(
                PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0];
        final int[] grantResults = (data != null) ? data.getIntArrayExtra(
                PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0];
        onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    

    结果进而进入回调activity的onRequestPermissionsResult,若activity未处理,且activit是FragmentActivity,则通过requestCode右移16位,进而传递结果到fragment的onRequestPermissionsResult(),完成整个权限请求流程。

    三、申请权限引起的生命周期变化

    由上面知道最终通过startActivityForResult来打开系统权限授权界面,我们在BaseActivity中相关方法中打印日志:

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG, "onResume: ");
    }
    
    @Override
    public void onPause() {
        super.onPause();
        Log.i(TAG, "onPause: ");
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG, "onSaveInstanceState: ");
    }
    
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        Log.i(TAG, "onRequestPermissionsResult: ");
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    

    然后请求权限,我们观察到:

    这里写图片描述

    权限结果回调,发生在onPause、onSaveInstanceState之后,onResume之前,即页面未处于前台显示。

    注意此时fragment事务提交时会状态丢失,如果执行ft.commit(),会报错。

    如此时不能DialogFragment.show(),因为DialogFragment.show()是ft.commit(),这个不允许状态丢失。

    public void show(FragmentManager manager, String tag) {
        mDismissed = false;
        mShownByMe = true;
        FragmentTransaction ft = manager.beginTransaction();
        ft.add(this, tag);
        ft.commit();
    }
    

    四、申请权限封装

    a、BaseActivity:

    public class BaseActivity extends AppCompatActivity {
        /**
         * 请求权限
         */
        public void requestDangerousPermissions(String[] permissions, int requestCode) {
            if (checkDangerousPermissions(permissions)){
                handlePermissionResult(requestCode, true);
                return;
            }
            ActivityCompat.requestPermissions(this, permissions, requestCode);
        }
    
        /**
         * 检查是否已被授权危险权限
         * @param permissions
         * @return
         */
        public boolean checkDangerousPermissions(String[] permissions) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                return true;
            }
            for (String permission : permissions) {
                if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED ||
                        ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
                    return false;
                }
            }
            return true;
        }
    
    
        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
            boolean granted = true;
            for (int result : grantResults) {
                if (result != PackageManager.PERMISSION_GRANTED) {
                    granted = false;
                }
            }
            boolean finish = handlePermissionResult(requestCode, granted);
            if (!finish){
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }
    
        /**
         * 处理请求危险权限的结果
         * @return
         */
        public boolean handlePermissionResult(int requestCode, boolean granted) {
            return false;
        }
    }
    

    b、BaseFragment:

    public class BaseFragment extends Fragment {
        /**
         * 请求权限
         *
         * @param permissions
         * @param requestCode
         */
        public void requestDangerousPermissions(String[] permissions, int requestCode) {
            if (checkDangerousPermissions(permissions)){
                handlePermissionResult(requestCode, true);
                return;
            }
            requestPermissions(permissions, requestCode);
        }
    
        /**
         * 检查是否已被授权危险权限
         * @param permissions
         * @return
         */
        public boolean checkDangerousPermissions(String[] permissions) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                return true;
            }
            if (getActivity() == null){
                return false;
            }
            for (String permission : permissions) {
                if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED ||
                        ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {
                    return false;
                }
            }
            return true;
        }
    
        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
            boolean isGranted = true;
            for (int result : grantResults) {
                if (result != PackageManager.PERMISSION_GRANTED) {
                    isGranted = false;
                }
            }
    
            if (!handlePermissionResult(requestCode, isGranted)){
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }
    
        /**
         * 处理请求危险权限的结果
         *
         * @param requestCode
         * @param isGranted 是否允许
         * @return
         */
        public boolean handlePermissionResult(int requestCode, boolean isGranted) {
            return false;
        }
    }
    

    c、使用,如打电话:

    private void attemptToCall(String phone) {
        if (!isIntentExisting(getContext(), Intent.ACTION_DIAL)) {
            Toast.makeText(getContext(), "该设备不能打电话", Toast.LENGTH_SHORT).show();
            return;
        }
        mPhone = phone;
        requestDangerousPermissions(callPermission, 88);
    }
    
    @Override
    public boolean handlePermissionResult(int requestCode, boolean isGranted) {
        if (requestCode == 88){
            final String phone = mPhone;
            getView().post(new Runnable() {
                @Override
                public void run() {
                    call(phone);
                }
            });
            mPhone = null;
            return true;
        }
    
        return super.handlePermissionResult(requestCode, isGranted);
    }
    
    private void call(String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    
    //判断电话应用是否存在
    public boolean isIntentExisting(Context context, String action) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(action);
        List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if (resolveInfo.size() > 0) {
            return true;
        }
        return false;
    }
    

    五、总结:

    a、当系统小于Android 6.0,只需要在AndroidManifest.xml注册权限即可使用(不包括某些手机厂商自定义的权限管理)。当系统大于等于Android 6.0时,既要在AndroidManifest.xml注册权限,又要去动态申请权限。

    b、申请权限时,最终通过startActivityForResult来打开系统权限授权界面,权限结果回调在onRequestPermissionsResult中,不会在onActivityResult中出现。

    c、requestCode取值范围:

    当activity为FragmentActivity时:

    • 在activity中请求权限时,requestCode有取值范围,为0 ~ 65535,权限回调结果在activity中。
    • 在fragment中请求权限时,requestCode有取值范围,为0 ~ 65535,权限回调结果先传递到activity中,若activity未拦截,再传递到fragment中。在activity中拦截时,可requestCode & 0xffff得到正确的requestCode。

    当activity为Activity时:

    • 在activity中请求权限时,requestCode取值范围无要求,权限结果回调在activity中。
    • 在fragment中请求权限时,requestCode取值范围无要求,权限结果直接回调在fragment中。在activity中不可拦截。

    d、不可短时间内重复执行同一请求权限代码,否则第一次之后的直接给定默认值结果,若结果grantResults会错误影响授权

    e、权限结果回调,发生在onPause、onSaveInstanceState之后,onResume之前,即页面未处于前台显示。

    备注:

    本文基于Android API 26

    本文测试手机华为P20 Pro

    Git示例代码:https://github.com/jinxiyang/RequestPermissions.git

    展开全文
  • 安卓权限说明

    2019-01-09 10:05:33
    android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问"properties”表在checkin数据库中,改值可以修改上传 ( Allows read/write access to the “properties” table in the checkin database, to ...

    android.permission.ACCESS_CHECKIN_PROPERTIES
    允许读写访问"properties”表在checkin数据库中,改值可以修改上传
    ( Allows read/write access to the “properties” table in the checkin database, to change values that get uploaded)

    android.permission.ACCESS_COARSE_LOCATION
    允许一个程序访问CellID或WiFi热点来获取粗略的位置
    (Allows an application to access coarse (e.g., Cell-ID, WiFi) location)

    android.permission.ACCESS_FINE_LOCATION
    允许一个程序访问精良位置(如GPS)
    (Allows an application to access fine (e.g., GPS) location)

    android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
    允许应用程序访问额外的位置提供命令
    (Allows an application to access extra location provider commands)

    android.permission.ACCESS_MOCK_LOCATION
    允许程序创建模拟位置提供用于测试
    (Allows an application to create mock location providers for testing)

    android.permission.ACCESS_NETWORK_STATE
    允许程序访问有关GSM网络信息
    (Allows applications to access information about networks)

    android.permission.ACCESS_SURFACE_FLINGER
    允许程序使用SurfaceFlinger底层特性
    (Allows an application to use SurfaceFlinger’s low level features)

    android.permission.ACCESS_WIFI_STATE
    允许程序访问Wi-Fi网络状态信息
    (Allows applications to access information about Wi-Fi networks)

    android.permission.ADD_SYSTEM_SERVICE
    允许程序发布系统级服务
    (Allows an application to publish system-level services).

    android.permission.BATTERY_STATS
    允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics)

    android.permission.BLUETOOTH
    允许程序连接到已配对的蓝牙设备(Allows applications to connect to paired bluetooth devices)

    android.permission.BLUETOOTH_ADMIN
    允许程序发现和配对蓝牙设备(Allows applications to discover and pair bluetooth devices)

    android.permission.BRICK
    请求能够禁用设备(非常危险)(Required to be able to disable the device (very *erous!).)

    android.permission.BROADCAST_PACKAGE_REMOVED
    允许程序广播一个提示消息在一个应用程序包已经移除后(Allows an application to broadcast a notification that an application package has been removed)

    android.permission.BROADCAST_STICKY
    允许一个程序广播常用intents(Allows an application to broadcast sticky intents)

    android.permission.CALL_PHONE
    允许一个程序初始化一个电话拨号不需通过拨号用户界面需要用户确认(Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.)

    android.permission.CALL_PRIVILEGED
    允许一个程序拨打任何号码,包含紧急号码无需通过拨号用户界面需要用户确认(Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed)

    android.permission.CAMERA
    请求访问使用照相设备(Required to be able to access the camera device. )

    android.permission.CHANGE_COMPONENT_ENABLED_STATE
    允许一个程序是否改变一个组件或其他的启用或禁用(Allows an application to change whether an application component (other than its own) is enabled or not. )

    android.permission.CHANGE_CONFIGURATION
    允许一个程序修改当前设置,如本地化(Allows an application to modify the current configuration, such as locale. )

    android.permission.CHANGE_NETWORK_STATE
    允许程序改变网络连接状态(Allows applications to change network connectivity state)

    android.permission.CHANGE_WIFI_STATE
    允许程序改变Wi-Fi连接状态(Allows applications to change Wi-Fi connectivity state)

    android.permission.CLEAR_APP_CACHE
    允许一个程序清楚缓存从所有安装的程序在设备中(Allows an application to clear the caches of all installed applications on the device. )

    android.permission.CLEAR_APP_USER_DATA
    允许一个程序清除用户设置(Allows an application to clear user data)

    android.permission.CONTROL_LOCATION_UPDATES
    允许启用禁止位置更新提示从无线模块(Allows enabling/disabling location update notifications from the radio. )

    android.permission.DELETE_CACHE_FILES
    允许程序删除缓存文件(Allows an application to delete cache files)

    android.permission.DELETE_PACKAGES
    允许一个程序删除包(Allows an application to delete packages)

    android.permission.DEVICE_POWER
    允许访问底层电源管理(Allows low-level access to power management)

    android.permission.DIAGNOSTIC
    允许程序RW诊断资源(Allows applications to RW to diagnostic resources. )

    android.permission.DISABLE_KEYGUARD
    允许程序禁用键盘锁(Allows applications to disable the keyguard )

    android.permission.DUMP
    允许程序返回状态抓取信息从系统服务(Allows an application to retrieve state dump information from system services.)

    android.permission.EXPAND_STATUS_BAR
    允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似Windows Mobile中的托盘程序(Allows an application to expand or collapse the status bar. )

    android.permission.FACTORY_TEST
    作为一个工厂测试程序,运行在root用户(Run as a manufacturer test application, running as the root user. )

    android.permission.FLASHLIGHT
    访问闪光灯,android开发网提示HTC Dream不包含闪光灯(Allows access to the flashlight )

    android.permission.FORCE_BACK
    允许程序强行一个后退操作是否在顶层activities(Allows an application to force a BACK operation on whatever is the top activity. )

    android.permission.FOTA_UPDATE
    暂时不了解这是做什么使用的,android开发网分析可能是一个预留权限.

    android.permission.GET_ACCOUNTS
    访问一个帐户列表在Accounts Service中(Allows access to the list of accounts in the Accounts Service)

    android.permission.GET_PACKAGE_SIZE
    允许一个程序获取任何package占用空间容量(Allows an application to find out the space used by any package. )

    android.permission.GET_TASKS
    允许一个程序获取信息有关当前或最近运行的任务,一个缩略的任务状态,是否活动等等(Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.)
    android.permission.HARDWARE_TEST
    允许访问硬件(Allows access to hardware peripherals. )

    android.permission.INJECT_EVENTS
    允许一个程序截获用户事件如按键、触摸、轨迹球等等到一个时间流,android 开发网提醒算是hook技术吧(Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.)

    android.permission.INSTALL_PACKAGES
    允许一个程序安装packages(Allows an application to install packages. )

    android.permission.INTERNAL_SYSTEM_WINDOW
    允许打开窗口使用系统用户界面(Allows an application to open windows that are for use by parts of the system user interface. )

    android.permission.INTERNET
    允许程序打开网络套接字(Allows applications to open network sockets)

    android.permission.MANAGE_APP_TOKENS
    允许程序管理(创建、催后、 z- order默认向z轴推移)程序引用在窗口管理器中(Allows an application to manage (create, destroy, Z-order) application tokens in the window manager. )

    android.permission.MASTER_CLEAR目前还没有明确的解释,android开发网分析可能是清除一切数据,类似硬格机

    android.permission.MODIFY_AUDIO_SETTINGS
    允许程序修改全局音频设置(Allows an application to modify global audio settings)

    android.permission.MODIFY_PHONE_STATE
    允许修改话机状态,如电源,人机接口等(Allows modification of the telephony state – power on, mmi, etc. )

    android.permission.MOUNT_UNMOUNT_FILESYSTEMS
    允许挂载和反挂载文件系统可移动存储(Allows mounting and unmounting file systems for removable storage. )

    android.permission.PERSISTENT_ACTIVITY
    允许一个程序设置他的activities显示(Allow an application to make its activities persistent. )

    android.permission.PROCESS_OUTGOING_CALLS
    允许程序监视、修改有关播出电话(Allows an application to monitor, modify, or abort outgoing calls)

    android.permission.READ_CALENDAR
    允许程序读取用户日历数据(Allows an application to read the user’s calendar data.)
    android.permission.READ_CONTACTS
    允许程序读取用户联系人数据(Allows an application to read the user’s contacts data.)
    android.permission.READ_FRAME_BUFFER
    允许程序屏幕波或和更多常规的访问帧缓冲数据(Allows an application to take screen shots and more generally get access to the frame buffer data)

    android.permission.READ_INPUT_STATE
    允许程序返回当前按键状态(Allows an application to retrieve the current state of keys and switches. )

    android.permission.READ_LOGS
    允许程序读取底层系统日志文件(Allows an application to read the low-level system log files. )

    android.permission.READ_OWNER_DATA
    允许程序读取所有者数据(Allows an application to read the owner’s data)

    android.permission.READ_SMS
    允许程序读取短信息(Allows an application to read SMS messages.)

    android.permission.READ_SYNC_SETTINGS
    允许程序读取同步设置(Allows applications to read the sync settings)

    android.permission.READ_SYNC_STATS
    允许程序读取同步状态(Allows applications to read the sync stats)

    android.permission.REBOOT
    请求能够重新启动设备(Required to be able to reboot the device. )

    android.permission.RECEIVE_BOOT_COMPLETED
    允许一个程序接收到 ACTION_BOOT_COMPLETED广播在系统完成启动(Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting. )

    android.permission.RECEIVE_MMS
    允许一个程序监控将收到MMS彩信,记录或处理(Allows an application to monitor incoming MMS messages, to record or perform processing on them. )

    android.permission.RECEIVE_SMS
    允许程序监控一个将收到短信息,记录或处理(Allows an application to monitor incoming SMS messages, to record or perform processing on them.)

    android.permission.RECEIVE_WAP_PUSH
    允许程序监控将收到WAP PUSH信息(Allows an application to monitor incoming WAP push messages. )

    android.permission.RECORD_AUDIO
    允许程序录制音频(Allows an application to record audio)

    android.permission.REORDER_TASKS
    允许程序改变Z轴排列任务(Allows an application to change the Z-order of tasks)

    android.permission.RESTART_PACKAGES
    允许程序重新启动其他程序(Allows an application to restart other applications)

    android.permission.SEND_SMS
    允许程序发送SMS短信(Allows an application to send SMS messages)

    android.permission.SET_ACTIVITY_WATCHER
    允许程序监控或控制activities已经启动全局系统中Allows an application to watch and control how activities are started globally in the system.

    android.permission.SET_ALWAYS_FINISH
    允许程序控制是否活动间接完成在处于后台时Allows an application to control whether activities are immediately finished when put in the background.

    android.permission.SET_ANIMATION_SCALE
    修改全局信息比例(Modify the global animation scaling factor.)

    android.permission.SET_DEBUG_APP
    配置一个程序用于调试(Configure an application for debugging.)

    android.permission.SET_ORIENTATION
    允许底层访问设置屏幕方向和实际旋转(Allows low-level access to setting the orientation (actually rotation) of the screen.)

    android.permission.SET_PREFERRED_APPLICATIONS
    允许一个程序修改列表参数PackageManager.addPackageToPreferred() 和PackageManager.removePackageFromPreferred()方法(Allows an application to modify the list of preferred applications with the PackageManager.addPackageToPreferred() and PackageManager.removePackageFromPreferred() methods.)

    android.permission.SET_PROCESS_FOREGROUND
    允许程序当前运行程序强行到前台(Allows an application to force any currently running process to be in the foreground.)

    android.permission.SET_PROCESS_LIMIT
    允许设置最大的运行进程数量(Allows an application to set the maximum number of (not needed) application processes that can be running. )

    android.permission.SET_TIME_ZONE
    允许程序设置时间区域(Allows applications to set the system time zone)

    android.permission.SET_WALLPAPER
    允许程序设置壁纸(Allows applications to set the wallpaper )

    android.permission.SET_WALLPAPER_HINTS
    允许程序设置壁纸hits(Allows applications to set the wallpaper hints)

    android.permission.SIGNAL_PERSISTENT_PROCESSES
    允许程序请求发送信号到所有显示的进程中(Allow an application to request that a signal be sent to all persistent processes)

    android.permission.STATUS_BAR
    允许程序打开、关闭或禁用状态栏及图标Allows an application to open, close, or disable the status bar and its icons.

    android.permission.SUBSCRIBED_FEEDS_READ
    允许一个程序访问订阅RSS Feed内容提供(Allows an application to allow access the subscribed feeds ContentProvider. )

    android.permission.SUBSCRIBED_FEEDS_WRITE
    系统暂时保留改设置,android开发网认为未来版本会加入该功能。

    android.permission.SYSTEM_ALERT_WINDOW
    允许一个程序打开窗口使用 TYPE_SYSTEM_ALERT,显示在其他所有程序的顶层(Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. )

    android.permission.VIBRATE
    允许访问振动设备(Allows access to the vibrator)
    android.permission.WAKE_LOCK
    允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失( Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming)
    android.permission.WRITE_APN_SETTINGS
    允许程序写入API设置(Allows applications to write the apn settings)
    android.permission.WRITE_CALENDAR
    允许一个程序写入但不读取用户日历数据(Allows an application to write (but not read) the user’s calendar data. )
    android.permission.WRITE_CONTACTS
    允许程序写入但不读取用户联系人数据(Allows an application to write (but not read) the user’s contacts data. )
    android.permission.WRITE_GSERVICES
    允许程序修改Google服务地图(Allows an application to modify the Google service map. )
    android.permission.WRITE_OWNER_DATA
    允许一个程序写入但不读取所有者数据(Allows an application to write (but not read) the owner’s data.)
    android.permission.WRITE_SETTINGS
    允许程序读取或写入系统设置(Allows an application to read or write the system settings. )
    android.permission.WRITE_SMS
    允许程序写短信(Allows an application to write SMS messages)
    android.permission.WRITE_SYNC_SETTINGS
    允许程序写入同步设置(Allows applications to write the sync settings)

    展开全文
  • 安卓Permission权限请求

    千次阅读 2020-03-28 13:06:57
    AndroidPermission,权限自动请求示例(所需权限被关闭时,会自动请求) 权限请求源码:(将应用的Activity设为PermissionActivity的子类,即可自动请求所需权限) package com.sc.demo; import android...
  • Android权限管理

    千次阅读 2019-07-17 12:39:52
    Android权限管理(PermissionsDispatcher框架使用)简述一、Android权限二、6.0以上权限管理 简述 由于对于安全考虑,Android对于权限的管理更加的严谨,以6.0位界分为两种处理方式:6.0以下系统还是保持旧的处理...
  • 安卓权限列表

    2018-10-02 21:19:50
      ... 危险权限   CALENDAR READ_CALENDAR WRITE_CALENDAR   CAMERA CAMERA   CONTACTS READ_CONTACTS WRITE_CONTACTS ...
  • Android权限管理详解

    万次阅读 2017-05-15 19:39:02
    概述Android安全架构规定:默认情况下,任何应用都没有权限执行对其他应用、操作系统或用户有不利影响的任何操作。这包括读写用户的私有数据(如联系人或电子邮件等)、读写其他应用的文件、执行网络访问、使设备...
  • 关于安卓录屏的权限问题

    千次阅读 2016-11-10 15:23:02
    关于安卓录屏的权限问题
  • 第三方浏览器需要有存储权限才能在浏览器里下载东西,apk本身并没有请求开启权限,请问如何在代码里给这个apk开启这项权限
  • android 命令行获取root权限

    万次阅读 2017-09-06 10:15:57
    先提权,后修改某一个文件夹的访问权限C:\Users\Administrator\Downloads\640wandroid\CatchBest>adb shell rk3399_firefly_box:/ $ su rk3399_firefly_box:/ # chmod 777 /dev/bus/usb/ -R rk3399_firefly_box:/ #
  • Android 相机相册权限设置

    千次阅读 2017-04-17 17:36:14
    在AndroidManifest.xml中设置相机和相册的权限
  • 安卓开发——获取安卓存储的权限

    千次阅读 2015-07-06 19:52:59
    最近用NDK开发opencv C++的安卓程序,调用了cvSaveImage函数,但是总是无法存储图片,各种崩溃,一度认为是因为opencv配置或者lib库、版本等出现了问题,调试了好多天,今天才发现原来是安卓存储权限没有获取的问题...
  • Android 9.0网络权限设置

    千次阅读 2019-07-20 09:29:59
    最近做的项目在9.0以下的手机运行,没有问题,到了9.0以后的手机上就没有数据,所以查到了这个方法,特别好用,分享给大家: 在AndroidManifest.xml中直接添加下面这句就...android:usesCleartextTraffic="true" ...
  • Android开发添加振动权限

    千次阅读 2017-03-31 20:53:47
    添加振动权限:在AndroidManifest.xml文件中添加这个权限 android.permission.VIBRATEAndroid开发添加声效,闪光灯等同理步骤如下: 打开项目中AndroidManifest.xml文件 点开permission选项卡–>add–>users ...
  • android读取文件权限

    万次阅读 2013-08-26 19:12:50
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • Android获得SD卡权限

    万次阅读 2018-05-30 22:10:08
    uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/&gt; ...
  • Android 如何获取应用通知权限

    万次阅读 2016-07-09 23:39:11
    Android 4.1: How to check notifications are disabled for the application? 不知道你看得懂代码吗,这个勾可以在代码里检查、设置勾选的。 如果想修改这个权限大概有三种方式: 1.通过代码反射系统类实现 系统...
  • uses-permission android:name="android.permission.SEND_SMS"/&gt;  &lt;!-- 阅读消息--&gt;  &lt;uses-permission android:name="android.permission.READ_SMS"/&gt; ...
  • Android 8.0 蓝牙权限踩的坑

    千次阅读 2018-04-09 12:04:18
    Android 7.0及以下要使用蓝牙获取蓝牙名字,rssi,major,minor,需要动态获取得到 “通过网络或者卫星对您的手机定位”这个位置权限,而Android8.0需要打开位置信息才可以得到蓝牙major,minor等信息...
1 2 3 4 5 ... 20
收藏数 246,512
精华内容 98,604
关键字:

安卓权限