问题描述
我想取回呼入的联系号码,并用它做什么样的做在http://blog.whitepages.com/2009/02/27/caller-id-by-whitepages-a-new-android-app-that-puts-telemarketers-on-alert/
能否请你帮我,因为我无法找到有关这方面的消息。我从哪里开始?如何弄个联系号码的?
好了,所以目前我的code看起来像下面。当我发出呼叫的CustomBroadcastReceiver捕获它和日志信息会被打印出来。我可以检索从包中的电话号码。但!我不能让兴田CustomPhoneStateListener工作。正如你可以看到我已经注册了我的customPhoneState监听器,接收器,但日志信息永远不会得到的来自CustomPhoneStateListener类打印出来。我是什么我在这里失踪?是我的想法是否正确?
<接收机器人:名称=。CustomBroadcastReceiver>
<意向滤光器>
<作用机器人:名称=android.intent.action.PHONE_STATE/>
&所述; /意图滤光器>
< /接收器>
< /用途>
<使用-SDK安卓的minSdkVersion =5/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.WRITE_CONTACTS/>
<使用-权限的Android:名称=android.permission.READ_PHONE_STATE/>
公共类CustomPhoneStateListener扩展PhoneStateListener {
私有静态最后字符串变量=CustomPhoneStateListener;
公共无效onCallStateChange(INT状态,串incomingNumber){
Log.v(TAG,我们都在里面!!!!!!!!!!!);
Log.v(TAG,incomingNumber);
开关(州){
案例TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG,振铃);
打破;
}
}
公共类CustomBroadcastReceiver扩展的BroadcastReceiver {
私有静态最后字符串变量=CustomBroadcastReceiver;
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
Log.v(TAG,我们都在里面!!!!!!!!!!!);
TelephonyManager电话=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener =新CustomPhoneStateListener();
telephony.listen(customPhoneListener,PhoneStateListener.LISTEN_CALL_STATE);
捆绑包= intent.getExtras();
串phoneNr = bundle.getString(incoming_number);
Log.v(TAG,phoneNr:+ phoneNr);
}
使用<$c$c>PhoneStateListener$c$c>.它有一个<$c$c>onCallStateChanged$c$c>处理程序;的提供的参数,你会得到一个是字符串
包含输入电话号码。
I would like to retrieve the incoming call's phonenumber and do something with it like the doin http://blog.whitepages.com/2009/02/27/caller-id-by-whitepages-a-new-android-app-that-puts-telemarketers-on-alert/
Could you please help me because I can't find any information about this.Where do i start and how do i get hold of the phonenumber?
Ok so currently my code looks like below. When I place the call the CustomBroadcastReceiver catches it and the log message is printed out. I can retrieve the telephone number from the bundle. But! I can't get hte CustomPhoneStateListener to work. As you can see I have registered my customPhoneState listener to the receiver but the log message never get's printed out from the CustomPhoneStateListener class. What am I my missing here?Is my thinking correct?
<receiver android:name=".CustomBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
public class CustomPhoneStateListener extends PhoneStateListener {
private static final String TAG = "CustomPhoneStateListener";
public void onCallStateChange(int state, String incomingNumber){
Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!");
Log.v(TAG, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "RINGING");
break;
}
}
public class CustomBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "CustomBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!");
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Bundle bundle = intent.getExtras();
String phoneNr= bundle.getString("incoming_number");
Log.v(TAG, "phoneNr: "+phoneNr);
}
Use PhoneStateListener
. It has an onCallStateChanged
handler; one of the supplied arguments you'll get is a String
containing the incoming phone number.
这篇关于检索安卓来电的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!