Search code examples
androidtextviewbroadcastreceiverphone-call

Why cant I set TextView to display incoming call phone number?


I have an app that replaces the standard incoming call screen with my own design. When someone calls, my custom screen pops up. This is good, but for some reason, my app fails to display the incoming phone number. The incoming phone number shows in LogCat, but when I try to set the TextView to that String, nothing shows. Here is the code that retrieves the incoming phone number:

Bundle extras = intent.getExtras();
    phoneNr = extras.getString("incoming_number");
    Log.v(TAG, "phoneNr: " + phoneNr);

As you can see, the String "phoneNr" displays the incoming phone number in LogCat. But when I try to use it to set the text of of the TextView in the class (IncomingCallRecieved) that displays my custom screen:

IncomingCallListener ICL = new IncomingCallListener(); // class for BroadcastReciever
textView_incomingNumber.setText(ICL.phoneNr);

the TextView remains blank.

Any suggestions as to why this is happening?


Solution

  • if phoneNr is integer do it like ""+phoneNr ,

    also making new IncomingCallListener() object will not going to refer the class which actually got the number..so either make that number variable public static and directly use that variable like classname.variablename