Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old December 6th, 2009, 05:13 AM   #1 (permalink)
New Member
 
Join Date: Dec 2009
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieve incoming call’s phone number in Android

I would like to retrieve the incoming call's phonenumber and do something with it like the do in Caller ID by WhitePages: A New Android App that Puts Telemarketers on Alert!

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 the 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?
Code:
<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" />
Code:
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;
        }       
}
Code:
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.d is offline  
Reply With Quote
Sponsors
Old April 16th, 2010, 03:52 PM   #2 (permalink)
New Member
 
Join Date: Apr 2010
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default caller id

Did you ever find a solution to this?
tfmegatron is offline  
Reply With Quote
Old September 9th, 2010, 09:46 AM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieve incoming call’s phone number in Android

In your CustomPhoneStateListener class you have:

public void onCallStateChange

Try changing to:

@Override
public void onCallStateChanged

I'm trying the same functionality myself. If I can get it to work, I'll post an update.
drewashby is offline  
Reply With Quote
Old September 9th, 2010, 01:27 PM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieve incoming call’s phone number in Android

Works for me now. Your original code, with the modification from my last post, and I now see the log messages from the CustomPhoneStateListener.

Thanks for the head start!
drewashby is offline  
Reply With Quote
Old December 31st, 2010, 02:55 AM   #5 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

very helpfull thread. I succesfully retrieve the incoming number and store it to a file

I have a related question:
Is there some flag or something which shows if the call is forwarded (redirected) ?

Best Regards
longjohn is offline  
Reply With Quote
Reply

Bookmarks

Tags
broadcastreceiver, incoming call, phonestatelistener


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incoming call vibrates phone while in use maryj459 Incredible - Support and Troubleshooting 3 December 7th, 2010 10:02 AM
'google' unknown (not in address book) incoming phone number mrsocks Android Applications 0 September 27th, 2010 05:07 PM
Support X10 - number of rings - incoming call phil_pe Sony Ericsson Xperia X10 1 September 21st, 2010 08:11 PM
Indication that incoming call is diverted from other number tomas.cze Android Applications 0 July 17th, 2010 07:44 AM
Phone speaks incoming number sldsnk Incredible - Support and Troubleshooting 1 June 20th, 2010 01:40 PM



All times are GMT -5. The time now is 12:38 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo


SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.