阻止来电和拨出电话?
我想创建一个应用程序,我可以在阻止或允许列表中设置不同的电话号码。是否可以阻止或仅允许某些电话号码,如果可以,我将如何执行此操作。预先感谢,乔纳森。
I would like to create a app that i can be able to set different phone numbers in a block or allow list. Is it possible to block or allow only certain phone numbers and if so how would i go about doing this. Thanks in advance, Jonathan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您必须创建一个带有注册 PhoneStateListener 的服务,该服务使您能够侦听有关电话状态更改的事件。因此,如果有人打电话,您可以在侦听器中捕获该事件并做出相应反应。您自己的 PhoneStateListener 可能如下所示:
}
在电话状态等于 CALL_STATE_RINGING 的情况下,如果来电号码等于“阻止号码列表”中的号码,您可以放置逻辑来阻止来电。要使其全部正常工作,您必须在服务中注册该侦听器(在 onCreate 方法中,并且不要忘记在 onDestroy 中取消注册),并向您的 android 清单添加一个权限,使您能够读取手机状态。
Sounds like you have to create a Service with a registered PhoneStateListener which enables you to listen to events regarding the change of the phone state. So if someone calls you can catch that event in your listener and react accordingly. Your own PhoneStateListener could look like this:
}
In the case where phone state equals CALL_STATE_RINGING you can place your logic to block the incoming call if the incoming number equals a number in your "blocked numbers list". To get it all working you have to register that listener in your service (in the onCreate method and don't forget to unregister it in onDestroy) and also add a permission to your android manifest which enables you to read the phone state.
首先创建一个广播接收器:
1)添加到清单
2)接收器:
现在只有在您至少启动应用程序一次后,这才会起作用。
(您可以使用另一个将调用 startActivity 的接收器来调用您的应用程序以在启动时启动服务)
其权限和声明是:
first thing create a broadcast reciever:
1)add to manifest
2)the reciever:
now this will only work once you started your app at least once.
(you can call your app to start a service on boot using another reciever that will call startActivity)
the permisions and declaration for it are: