Skip to content

Instantly share code, notes, and snippets.

@caseykulm
Created May 16, 2017 14:32
Show Gist options
  • Select an option

  • Save caseykulm/d799c3f0f3db4128c53c8205ae389c0a to your computer and use it in GitHub Desktop.

Select an option

Save caseykulm/d799c3f0f3db4128c53c8205ae389c0a to your computer and use it in GitHub Desktop.
Helper to get System Window permission
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
public class SystemWindowUtil {
private final Context appContext;
public SystemWindowUtil(Context appContext) {
this.appContext = appContext;
}
public void askForPermission() {
// Check if Android M or higher
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
// Show alert dialog to the user saying a separate permission is needed
// Launch the settings activity if the user prefers
Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
appContext.startActivity(myIntent);
}
}
public boolean havePermission() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
Settings.canDrawOverlays(appContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment