來電的電話號碼,我想找回來電的PHONENUMBER並用它做什麼像做 在http://blog.whitepages.com/2009/02/27/caller-id-by-whitepages-a-new-android-app-that-puts-telemarketers-on-alert/檢索的Android
能否請你幫我,因爲我無法找到有關這方面的消息。 我從哪裏開始,如何獲取語數?
好的,所以目前我的代碼如下所示。當我將呼叫置於CustomBroadcastReceiver中時,它會打印出日誌消息。我可以從包中找回電話號碼。但!我無法使CustomPhoneStateListener工作。正如你所看到的,我已將自定義電話狀態偵聽器註冊到接收器,但日誌消息從未從CustomPhoneStateListener類打印出來。我在這裏錯過了什麼? 我的想法是否正確?
<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);
}
能否請您提供一個例子實施? – jakob
我對這個問題的回答可能有幫助[鏈接](http://stackoverflow.com/questions/10136490/androidget-phone-number-of-present-incoming-and-outgoing-call/11182720#11182720) – Gary