title: How to use system_alert_window popup in java
body: <p>I need to have my app draw over other apps, and I tried getting <code>SYSTEM_ALERT_WINDOW</code> permission shown below.</p>
  
  <pre><code>public class excessiveusageactivity extends AppCompatActivity {
  
      static final int REQUEST_OVERLAY_PERMISSION = 1; //request code
      TextView result;
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          result = findViewById(R.id.result);
       if (requestCode == REQUEST_OVERLAY_PERMISSION) {
           if (Settings.canDrawOverlays(this)) {
               Toast permissionok = Toast.makeText(this, "permission granted!", Toast.LENGTH_SHORT);
               permissionok.show();
               //permission granted do stuff
               result.setText("yay");
           }else{
               Toast permissionnotgrantedtoast = Toast.makeText(this,"permission request failed, try again!", Toast.LENGTH_LONG);
               permissionnotgrantedtoast.show();
               //permission not granted
               result.setText("not granted");
           }
       }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_excessiveusageactivity);
  
          if(
                  Settings.canDrawOverlays(this)
          ) {
              // ask for overlay permission
              Intent requestoverlaypermissionintent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                      Uri.parse("package:" + getPackageName()));
              startActivityForResult(requestoverlaypermissionintent, REQUEST_OVERLAY_PERMISSION);
              result.setText("here");
          }
      }
  }
  </code></pre>
  
  <p>I got this code from <a href="https://stackoverflow.com/questions/36016369/system-alert-window-how-to-get-this-permission-automatically-on-android-6-0-an">here</a> by user Jayman Jani.</p>
  
  <p>I wish to make a custom system alert popup when the user uses an app for X minutes/hour consecutively, but I can't seem to find any information on how to set up this popup. I am quite new to all this so it would be great if someone can explain it mostly step-by-step. Thank you!</p>