Created
May 16, 2017 14:32
-
-
Save caseykulm/d799c3f0f3db4128c53c8205ae389c0a to your computer and use it in GitHub Desktop.
Helper to get System Window permission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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