Android - Cant see the incoming calls when LayoutParams.TypeSystemError is displayed

馋奶兔 提交于 2019-12-31 05:39:06

问题


I'm developing lock screen app. Here Lock screen is displayed on the top of the screen using this command "WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;"

But my problem is I can't See the Incoming call Window when the custom lock screen is displayed. Incoming call window is not overrided over my custom lock screen.

1) Is there any permission required for displaying the incoming call window.?

2) We have to add any other codes for answering the incoming class

This is my Lockscreen receiver class

public class LockScreenReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(action.equals(Intent.ACTION_SCREEN_OFF) || action.equals(Intent.ACTION_BOOT_COMPLETED))
        {
            Intent i = new Intent(context, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }

In the normal lock screen apps -> They can attend the incoming calls and after attending that call, lock screen is displayed. How ????

Please help me. Thanks in advance


回答1:


  1. Add receiver in the manifest and ask for permission

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

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

  2. Create class IncomingCall

    public class IncomingCall extends BroadcastReceiver {
    
    public void onReceive(Context context, Intent intent) {
    
        try {
                TelephonyManager telephonyManager = (TelephonyManager) context
                        .getSystemService(Context.TELEPHONY_SERVICE);
    
                MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
    
                // Register listener for LISTEN_CALL_STATE
                telephonyManager.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    
  3. Implement PhoneStateListener in LockScreen and call onCallStateChanged

    private class LockScreen extends AppCompatActivity implements PhoneStateListener{
    
        public void onCallStateChanged(int state, String incomingNumber) {
    
            //Disable lockscreen when calls come
    
        }
    


来源:https://stackoverflow.com/questions/43533933/android-cant-see-the-incoming-calls-when-layoutparams-typesystemerror-is-displ

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