【问题标题】:Android - Cant see the incoming calls when LayoutParams.TypeSystemError is displayedAndroid - 显示 LayoutParams.TypeSystemError 时看不到来电
【发布时间】:2017-04-21 04:24:08
【问题描述】:

我正在开发锁屏应用。使用此命令“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);
        }
    }

在普通锁屏应用中 -> 他们可以接听来电,接听电话后,会显示锁屏。怎么样????

请帮助我。提前致谢

【问题讨论】:

    标签: java android service lockscreen android-broadcastreceiver


    【解决方案1】:
    1. 在清单中添加接收者并请求许可

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

      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt;&lt;/uses-permission&gt;

    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. LockScreen 中实现PhoneStateListener 并调用onCallStateChanged

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 2019-01-31
      相关资源
      最近更新 更多