AndroidtargetSdkVersion31TelephonyManagerlistenSecurityException
创始人
2024-08-21 15:00:34
0

在Android targetSdkVersion 31 中,TelephonyManager 的 listen 方法被修改以只能接收通过 registerCallback 注册的回调。如果直接使用 listen 方法,则会抛出 SecurityException 异常。

解决办法是使用 registerTelephonyCallback 方法注册回调。以下是代码示例:

TelephonyManager telephonyManager = getSystemService(TelephonyManager.class);
TelephonyCallback telephonyCallback = new TelephonyCallback();
telephonyManager.registerTelephonyCallback(Executors.newSingleThreadExecutor(), telephonyCallback);

其中,TelephonyCallback 是你自己实现的类,需要继承 TelephonyCallback 类,例如:

private class TelephonyCallback extends TelephonyCallback.Callback {
    @Override
    public void onCallStateChanged(int state, @Nullable String phoneNumber) {
        super.onCallStateChanged(state, phoneNumber);
        // 处理电话状态改变的逻辑
    }
}

在 TelephonyCallback 类中实现需要处理的方法即可。

相关内容

热门资讯

透视ai!智星菠萝可以辅助吗,... 透视ai!智星菠萝可以辅助吗,德州辅助工具到底怎么样,必备教程(确实存在有挂);值得一提的是,智星菠...
透视安装!hhpoker免费透... 透视安装!hhpoker免费透视脚本,aapoker可以开挂吗,重大来袭(有挂透明)1、构建自己的微...
透视线上!hhpoker透视脚... 透视线上!hhpoker透视脚本,拱趴大菠萝万能辅助器,可靠技巧(都是真的是有挂)准备好在hhpok...
透视线上!红龙poker透视,... 1、透视线上!红龙poker透视,德扑圈透视,细节方法(往昔有挂);详细教程。2、红龙poker透视...
透视透视!红龙poker辅助,... 透视透视!红龙poker辅助,aapoker有脚本吗,实测交流(有挂教程)是一款可以让一直输的玩家,...
透视挂!wepoker底牌透视... 透视挂!wepoker底牌透视脚本下载,hhpoker到底可以作弊吗,必赢教程(起初真的有挂);支持...
透视app!aapoker辅助... 透视app!aapoker辅助插件工具下载,hhpoker辅助下载,专业讨论(有挂方法)1、每一步都...
透视真的!hhpoker辅助软... 透视真的!hhpoker辅助软件,poker红龙辅助,辅助教程(竟然存在有挂);原来确实真的有挂(需...
透视安装!hhpoker辅助软... 透视安装!hhpoker辅助软件,wepoker底牌透视脚本http,揭秘真相(有挂总结);wepo...
透视好友房!aapoker辅助... 透视好友房!aapoker辅助工具存在吗,wpk德州局怎么透视,揭秘教程(一向是有挂);是一款可以让...