title: How to check whether Media Projection API Service Permission Enabled or not
body: <p>I am working in an app where I am taking screenshots using Media Projection API. I am able to successfully get the screenshot of the user foreground screen but unfortunately am not able to get the state whether user has already provided Screen capturing permission or not.</p>
  
  <p><strong>Requirement</strong>: I need to show the permission window only once when the user has not provided Screen capture permission.</p>
  
  <p><strong>Current Behaviour</strong>: Each time the permission window is getting displayed while launching the app. Please find the screenshot below</p>
  
  <p><a href="https://i.stack.imgur.com/tb7Lt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tb7Lt.jpg" alt="enter image description here"></a></p>
  
  <p>Code that I am using to show the permission window in MainActivity:</p>
  
  <pre><code>MediaProjectionManager mgr = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
  
                  startActivityForResult(mgr.createScreenCaptureIntent(),
                          Constants.RESULT_CODE.SCREENSHOT);
  </code></pre>
  
  <p>And after if the user choose YES from the permission window, I am starting a Service as below:</p>
  
  <pre><code>  @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
          if (requestCode == Constants.RESULT_CODE.SCREENSHOT) {
  
  
              if (resultCode == RESULT_OK) {
  
                  Intent intent = new Intent(this, WindowChangeDetectingService.class);
                  intent.putExtra(Constants.INTENT_KEY.SCREENSHOT, resultCode);
                  intent.putExtra(Constants.INTENT_KEY.SCREENSHOT_DATA, data);
                  startService(intent);
                  finish();
              }
          }
  
      }
  </code></pre>
  
  <p><strong>Expected Output</strong>:</p>
  
  <p>I am figuring out the solution to check the simple permission check which tells whether the permission has already provided or not using any boolean check before requesting for the Media Projection Services permission window something like </p>
  
  <pre><code>if(isMediaPermissionAlreadyEnabled){
  
   MediaProjectionManager mgr = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
  
                      startActivityForResult(mgr.createScreenCaptureIntent(),
                              Constants.RESULT_CODE.SCREENSHOT);
  
  }
  </code></pre>
  
  <p>I have been struggling hard to get the solution for Permission check since 3 days and I am not able to find any work around to solve my use case. It would be really helpful if someone provide me some suggestions or tips to resolve my issue. Thanks in advance.</p>