I saw this
But not works for me.
I am going to display Toast
, in my code:
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
Log.d("MyPhoneListener", state + " incoming no:" + incomingNumber);
if (state == 1) {
String msg = "New Phone Call Event. Incomming Number : " + incomingNumber;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(getApplicationContext(), msg, duration);
toast.show();
}
}
}
But i have compile time exception neither in getApplicationContext()
or in MainActivity.this
, or getActivity()
.
What is the solution?