How to show incoming call notification in android

2020-02-26 10:13发布

I want to display one dialog box after incoming call, so that I can run my application in background while receiving call.

How to catch that incoming call in android application???

标签: android
2条回答
▲ chillily
2楼-- · 2020-02-26 10:50

In AndroidManifest.xml you shoud make a receiver:

<receiver android:name="IncomingCallInterceptor">                    
    <intent-filter>
         <action android:name="android.intent.action.PHONE_STATE"/>   
    </intent-filter>
</receiver>

and declare permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Then,

public class IncomingCallInterceptor extends BroadcastReceiver {


@Override 
public void onReceive(final Context context, Intent intent) {                                         
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                         


    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {                                   

        // Phone is ringing

    }


}

}
查看更多
来,给爷笑一个
3楼-- · 2020-02-26 11:01

Maybe this broadcast intent is what you need ACTION_PHONE_STATE_CHANGED

查看更多
登录 后发表回答