android开发:Manifest.permission常用的权限


网络相关的:

android.permission.INTERNET 允许程序打开网络套接字

 android.permission.CHANGE_NETWORK_STATE 允许程序改变网络连接状态 

android.permission.ACCESS_NETWORK_STATE   允许程序访问有关GSM网络信息

 

位置相关:

android.permission.WRITE_GSERVICES
允许程序修改Google服务地图(Allows an application to modify the Google service map. )


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.CONTROL_LOCATION_UPDATES
允许启用禁止位置更新提示从无线模块(Allows enabling/disabling location update notifications from the radio. )


 

wifi相关:

android.permission.ACCESS_COARSE_LOCATION   允许一个程序访问CellID或WiFi热点来获取粗略的位置

android.permission.ACCESS_WIFI_STATE   允许程序访问Wi-Fi网络状态信息

android.permission.CHANGE_WIFI_STATE   允许程序改变Wi-Fi连接状态

 

蓝牙相关:

android.permission.BLUETOOTH   允许程序连接到已配对的蓝牙设备

android.permission.BLUETOOTH_ADMIN   允许程序发现和配对蓝牙设备

 

广播:

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.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.READ_SMS
允许程序读取短信息(Allows an application to read SMS messages.)

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

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

android.permission.WRITE_SMS
允许程序写短信(Allows an application to write SMS messages)

android.permission.RECEIVE_MMS
允许一个程序监控将收到MMS彩信,记录或处理(Allows an application to monitor incoming MMS 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.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.PROCESS_OUTGOING_CALLS
允许程序监视、修改有关播出电话(Allows an application to monitor, modify, or abort outgoing calls)


android.permission.READ_CONTACTS
允许程序读取用户联系人数据(Allows an application to read the user’s contacts data.)

android.permission.WRITE_CONTACTS
允许程序写入但不读取用户联系人数据(Allows an application to write (but not read) the user’s contacts data. )

 


系统级权限:

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

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.DUMP
允许程序返回状态抓取信息从系统服务(Allows an application to retrieve state dump information from system services.)

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

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

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

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.SET_ACTIVITY_WATCHER
允许程序监控或控制activities已经启动全局系统中Allows an application to watch and control how activities are started globally in the system.

android.permission.WRITE_SETTINGS
允许程序读取或写入系统设置(Allows an application to read or write the system settings. )

android.permission.WRITE_SYNC_SETTINGS
允许程序写入同步设置(Allows applications to write the sync settings)

 

 

 


访问设备相关:

android.permission.HARDWARE_TEST
允许访问硬件(Allows access to hardware peripherals. )


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

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

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

android.permission.CAMERA

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

android.permission.VIBRATE


允许访问振动设备(Allows access to the vibrator)

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.BATTERY_STATS
允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics)

android.permission.DEVICE_POWER

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

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

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

android.permission.READ_FRAME_BUFFER
允许程序屏幕波或和更多常规的访问帧缓冲数据(Allows an application to take screen shots and more generally get access to the frame buffer data)

 


删除相关:

 

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.DELETE_CACHE_FILES
允许程序删除缓存文件(Allows an application to delete cache files)

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

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

 

 

其它权限:


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.DIAGNOSTIC
允许程序RW诊断资源(Allows applications to RW to diagnostic resources. )


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.FORCE_BACK
允许程序强行一个后退操作是否在顶层activities(Allows an application to force a BACK operation on whatever is the top activity. )

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.MODIFY_AUDIO_SETTINGS
允许程序修改全局音频设置(Allows an application to modify global audio settings)

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


ndroid.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_SYNC_SETTINGS
允许程序读取同步设置(Allows applications to read the sync settings)

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

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.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.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_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.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_SYNC_SETTINGS
允许程序写入同步设置(Allows applications to write the sync settings)
 
<think>嗯,用户这次提了一个具体的Android升级兼容性问题,看来是在开发过程中遇到了实际的权限错误。用户提到从Android14升级到Android15时出现java.lang.AssertionError,特别指出蓝牙模块的targetSDK35和READ_SMS、POST_NOTIFICATIONS权限问题。这应该是个专业开发者遇到的真实痛点。从用户引用资料来看,ta已经做了功课:知道AssertionError通常和断言失败有关(引用2),看过Mockito测试相关的异常处理案例(引用3),甚至研究过用显式异常替代断言的方案(引用4)。不过核心矛盾在于Android系统升级后权限机制的变更——这正是Android开发最头疼的适配问题之一。需要重点解决几个层面:首先明确AssertionError的具体触发场景,用户提到targetSDK35的蓝牙模块,怀疑是新系统对旧权限模型的兼容断裂;其次是特殊权限READ_SMS的授予机制变更,Android14开始需要精细处理;最后是POST_NOTIFICATIONS这种运行时权限的显式请求逻辑调整。注意到用户特别强调“权限无法默认授予”,这很关键。Android15可能废弃了旧版的自动授予机制,尤其是对于短信读取这种敏感权限。解决方案需要覆盖三方面:清单声明的新要求、动态请求的最佳实践、以及适配新蓝牙权限的特殊处理(BLUETOOTH_CONNECT等权限组需要精确定义)。测试部分也不能忽视,用户引用的资料3显示ta在Mockito测试时遇到过类似异常,可能需要同步调整单元测试对权限请求流程的模拟逻辑。另外所有代码示例必须确保兼容Android15新特性,比如要用ContextCompat检查权限。考虑到用户显然是专业开发者,回复需要直接切入技术细节,提供可落地的代码方案,同时提醒关键的时间节点——比如GooglePlay要求11月起新应用必须targetAndroid15。把蓝牙适配和特殊权限处理作为独立章节可能更清晰,因为这类问题常需要分别处理。</think> 以下是针对Android 14升级至Android 15时出现的`java.lang.AssertionError`权限问题的完整解决方案,重点解决蓝牙模块(`com.android.bluetooth`)在targetSDK 35下`READ_SMS`和`POST_NOTIFICATIONS`权限的适配问题: --- ### 问题根源分析 1. **权限模型变更** Android 15(API 35)进一步收紧敏感权限控制: - `READ_SMS` 被归类为**高危权限**,需显式动态申请 - `POST_NOTIFICATIONS` 从Android 13(API 33)起已是**运行时权限** - `BLUETOOTH_CONNECT` 等新蓝牙权限需精确声明 2. **`AssertionError`触发原因** 当应用试图在未正确申请权限时直接调用相关API(如通过蓝牙访问短信),系统触发断言异常,常见于: ```log java.lang.AssertionError: Impossible state: Permission not granted: android.permission.READ_SMS ``` --- ### 分步解决方案 #### 1. **清单文件声明 (AndroidManifest.xml)** ```xml <!-- 必须显式声明所有权限 --> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <!-- Android 12+ 新增的蓝牙权限 --> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <!-- 适配Android 15的权限升级 --> <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="35" /> ``` #### 2. **运行时权限请求** ```java // 在启动蓝牙服务前检查权限 private void checkPermissions() { String[] requiredPermissions = new String[]{ Manifest.permission.READ_SMS, Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.BLUETOOTH_CONNECT }; List<String> ungranted = new ArrayList<>(); for (String perm : requiredPermissions) { if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) { ungranted.add(perm); } } if (!ungranted.isEmpty()) { ActivityCompat.requestPermissions(this, ungranted.toArray(new String[0]), REQ_CODE_PERMISSIONS); } else { initBluetoothService(); // 权限已获取,初始化蓝牙 } } // 处理权限请求结果 @Override public void onRequestPermissionsResult(int code, String[] permissions, int[] results) { if (code == REQ_CODE_PERMISSIONS) { for (int i = 0; i < results.length; i++) { if (results[i] != PackageManager.PERMISSION_GRANTED) { // 关键权限缺失时终止操作 if (permissions[i].equals(Manifest.permission.BLUETOOTH_CONNECT)) { Toast.makeText(this, "蓝牙功能需要定位权限", Toast.LENGTH_SHORT).show(); finish(); return; } } } initBluetoothService(); } } ``` #### 3. **蓝牙服务初始化适配** ```java private void initBluetoothService() { try { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter == null || !adapter.isEnabled()) { // 处理蓝牙未开启情况 return; } // Android 15需使用新的BluetoothManager BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); BluetoothDevice device = manager.getAdapter().getRemoteDevice(deviceAddress); // 执行需要READ_SMS权限的蓝牙操作 if (checkSmsPermission()) { performBluetoothOperation(device); } } catch (SecurityException e) { Log.e(TAG, "权限缺失: " + e.getMessage()); // 避免触发AssertionError } } private boolean checkSmsPermission() { return ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED; } ``` #### 4. **自动化测试修复(Mockito示例)** ```java @Test public void testBluetoothWithPermissions() { // 模拟授权状态 when(mockContext.checkPermission(eq(Manifest.permission.READ_SMS), anyInt(), anyInt())) .thenReturn(PackageManager.PERMISSION_GRANTED); // 执行测试方法 testClass.performBluetoothOperation(); // 验证未抛出断言错误 } ``` --- ### 关键注意事项 1. **权限分级处理** - `READ_SMS`:需在**用户可见的Activity**中请求,不可在后台服务直接调用 - `POST_NOTIFICATIONS`:首次使用通知功能时需弹出系统对话框 2. **Bluetooth适配要点** - **Android 12+**:必须使用`BLUETOOTH_CONNECT`替代`BLUETOOTH` - **设备扫描**:需要同时声明`BLUETOOTH_SCAN`和`ACCESS_FINE_LOCATION` 3. **兼容性处理** ```java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { requestPermissions(new String[]{Manifest.permission.BLUETOOTH_CONNECT}, REQ_CODE); } else { requestPermissions(new String[]{Manifest.permission.BLUETOOTH}, REQ_CODE); } ``` --- ### 验证流程 1. 在**Android 15模拟器**中测试权限弹窗是否正常触发 2. 使用**ADB命令**检查权限授予状态: ```bash adb shell dumpsys package com.your.package | grep READ_SMS ``` 3. 监控Logcat过滤错误: ```log adb logcat | grep -E 'Bluetooth|Sms|Permission' ``` > **重要提示**:Google Play要求2023年11月起**所有新应用必须targetSdkVersion>=34**,现有应用升级需在2024年11月前完成[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值