我正在尝试获取来电的“incoming_number”。我搜索并找到这篇文章,但它已经过时了,我不能'似乎无法与 Google 最新版本的 Android (4.0.3) 配合使用。
阅读另一篇文章后,似乎触发呼叫传入的最简单(也可能是唯一)的方法是设置一个基于 PhoneStateListener 做出反应的 BroadcastReceiver,提到的: 约翰·费米内拉。
当我以同样的方式设置它时,它会显示在 jakob 的帖子中,调试器永远不会落入 onCallStateChanged () 方法,并且我已经做了 jakob 的注释中提到的修改post.. (onCallStateChange"d"())
但是,我仍然没有运气,我认为这种获取传入号码的方法已被弃用,并且在 ICS (4.0.3) 中不起作用。还有其他传统或半传统的方法可以实现这一目标吗?
I am trying to grab the "incoming_number" of an incoming phone call. I searched and found this post, but it's outdated and I can't seem to get this to work with Google's latest version of Android (4.0.3).
After reading the other post it seems that the easiest (and possibly only) way to trigger that a call is coming in is to set a BroadcastReceiver that reacts based on the PhoneStateListener, mentioned by: John Feminella.
When I set this up the same way it is displayed in the post by jakob the debugger never drops into the onCallStateChanged() method, and I have made the modifications that were mentioned in the remarks in jakob's post.. (onCallStateChange"d"())
However, I still am getting no luck and I figured that this method of grabbing the incoming_number has been deprecated and not working in ICS (4.0.3). Are there any other conventional or semi-conventional ways to achieve this?
发布评论
评论(2)
为了让它在较新版本的 Android(4.0.3 等)中工作,您需要确保您的 minSdkVersion 为 3。我的代码的问题是我的 minSdkVersion 是 7..
希望这可以帮助其他试图解决这个问题的人! :)
In order to get this to work in newer versions of Android (4.0.3 etc) you need to make sure that your minSdkVersion is 3.. The issue with my code was that my minSdkVersion was 7..
Hope this helps others trying to figure this out! :)
jakob 没有提到的是,您必须在使用 PhoneStateListener 之前注册它。在您想要拦截来电号码之前,将以下代码放置在某个位置(例如,在您的活动的 onCreate 方法中):
然后应该触发 onCallStateChanged 方法。我不知道这个方法在 4.0.3 中已被弃用。但我认为作为一个快速解决方案,这应该还是可以的。
希望对您有所帮助。
干杯
What jakob does not mention is that you have to register the PhoneStateListener prior to use it. Put the following code somewhere before you want to intercept the incoming calls number (e.g. in the onCreate method of your activity):
Then the onCallStateChanged method should be triggered. I didn't know that this method is deprecated in 4.0.3. But I think as a quick solution this should still be fine.
Hope to have helped you.
Cheers