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

后端 未结 1 991
抹茶落季
抹茶落季 2021-01-27 23:57

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 prob

相关标签:
1条回答
  • 2021-01-28 00:51
    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
      
          }
      
    0 讨论(0)
提交回复
热议问题