I am creating an application which performs a certain set of operation for the calls i receive or make.But the application is not able to detect the caller id even though i have provided the required permissions.
My Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
My BrodcastReciever:
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
System.out.println("incomingNumber : "+incomingNumber);
if(state == TelephonyManager.CALL_STATE_IDLE && clientContacts.containsKey(incomingNumber)) {
sharedPreferences.edit()
.putString("callerName",clientContacts.get(incomingNumber))
.apply();
final Intent intent1 = new Intent(context, ClientInteractionDialogService.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
ContextCompat.startForegroundService(context, intent1);
}
},500);
}
}
},PhoneStateListener.LISTEN_CALL_STATE);