Android高版本适配总结1

本文详细介绍了在Android 6.0及以上版本中进行权限适配、写短信操作、拦截短信、查看App使用情况、获取运行App及清除App缓存的方法。针对每个适配点,提供了相应的API使用注意事项和第三方库推荐。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


如有转载,请申明:
转载至 http://blog.youkuaiyun.com/qq_35064774/article/details/52950674


目录

  1. 权限适配
  2. 写短信操作适配
  3. 拦截短信操作适配
  4. 查看App使用情况适配
  5. 获取所有运行的App
  6. 清除App缓存

权限适配(安卓6.0 API api23)

安卓6.0给权限进行了分类,所以就出现了运行时权限。运行时权限需要在代码中申请。
这里我收集了一份 Android 6.0的运行时权限

如果你的App涉及的运行时权限很少,可以考虑在需要使用的时候再申请,如果申请成功,就运行相应的代码,申请失败就给出提示。
以下是申请权限的流程。

// check whether has specific permission
if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_CONTACTS)
    == PackageManager.PERMISSION_GRANTED) {

    // has permission or no need permission

} else {
    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {

        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.
        ActivityCompat.requestPermissions(thisAct
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值