简体   繁体   English

在Android中处理来电

[英]Handling incoming call in android

In my app i want to detect incoming call and i want to hide default incoming call layout with my custom layout,far now i have managed to get the state of incoming call but i'm not able to hide the default incoming call screen...below is my code and my android manifest file...any help will be appreciated.. 在我的应用程序中,我想检测呼入电话,并希望使用自定义布局隐藏默认的呼入电话布局,到目前为止,我已经设法获取了呼入电话的状态,但是我无法隐藏默认的呼入屏幕。 .below是我的代码和我的android清单文件...任何帮助将不胜感激..

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Log.i("DEBUG", "on recive called");
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
    String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state))
    {
        abortBroadcast();
        Log.d("MPR", "Its Ringing [" + number + "]");
        //start activity
        Intent i = new Intent();
        i.setClassName("com.ezest.callerid", "com.ezest.callerid.CustomCallActivity");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }

    if (TelephonyManager.EXTRA_STATE_IDLE.equals(state))
    {
        Log.d("MPR", "Its Idle");
    }
    if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state))
    {
        Log.d("MPR", "Its OffHook");
    }

}

Manifest 表现

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <receiver android:name="MYPhoneStateListener">
        <intent-filter android:priority="999999">
            <action android:name="android.intent.action.PHONE_STATE"></action>
        </intent-filter>
    </receiver>
    <activity
        android:label="@string/app_name"
        android:name=".CallerIDActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="CustomCallActivity">
    </activity>

</application>

when defined action is happened android operating system send broadcast to all defined broadcastreceiver for this action. 当发生定义的操作时,Android操作系统会为此操作将广播发送到所有定义的broadcastreceiver。 it does this job according to priority order. 它根据优先级顺序执行此工作。 I can see you have done it. 我可以看到你已经做到了。 copy that code where you want to cancel broadcast. 将该代码复制到要取消广播的位置。

abortBroadcast()

Android operating system will stop broadcasting to other broadcastreceivers Android操作系统将停止向其他广播接收器广播

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM