Android - 显示LayoutParams.TypeSystemError时无法看到传入的调用

时间:2017-04-21 04:24:08

标签: java android service lockscreen android-broadcastreceiver

我正在开发锁屏应用。这里使用此命令“WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;”在屏幕顶部显示锁定屏幕。

但我的问题是,当显示自定义锁定屏幕时,我看不到来电窗口。来自我的自定义锁定屏幕未覆盖来电窗口。

1)是否需要显示来电窗口的许可。?

2)我们必须添加任何其他代码来回答传入的课程

这是我的锁屏接收器类

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);
        }
    }

在普通锁屏应用中 - >他们可以参加来电,在看到该电话后,会显示锁定屏幕。怎么????

请帮帮我。提前致谢

1 个答案:

答案 0 :(得分:0)

  1. 在清单中添加接收者并请求许可

    <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. 创建课程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. PhoneStateListener中实施LockScreen并致电onCallStateChanged

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