How to get alert dialog only after disconnect call?

扶醉桌前 提交于 2019-12-02 14:01:23

You have written your code in wrong place. This code

Intent i = new Intent(context, Disp_Alert_dialog.class);   
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", incomingNumber); 
context.startActivity(i);

will be in else..if condition instead of if condition.

Rishabh Singh Bisht

You condition is wrong. You are using else block of

if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)

It will run whenever call state changes to 'Ideal' or 'off hook' (in outgoing call - when dialed and call is disconnected, in incoming call - when call is picked up and call is disconnected).

If you want to show dialogue only while disconnecting call, use

if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDEAL)

and write code in if block

As for number, you cannot get number that way as it is only valid for ringing state. A work around would be using a ContentObserver on CallLog. Its onChange() will be called whenever there is a change in call log. You can then take number from call log. But you will need to have a part of your application active for this. Use in a Service may be.

Note- In some devices message also comes in call log data. So check if last entry in call log in of call type or not before showing your dialogue

This may help you in using content observer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!