开发者

How to show incoming call notification in android application

开发者 https://www.devze.com 2022-12-29 00:02 出处:网络
I want to display one dialog box after incoming call, so that I can run my application in background w开发者_JAVA百科hile receiving call.

I want to display one dialog box after incoming call, so that I can run my application in background w开发者_JAVA百科hile receiving call.

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


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

    }


}

}


Maybe this broadcast intent is what you need ACTION_PHONE_STATE_CHANGED

0

精彩评论

暂无评论...
验证码 换一张
取 消