Marshmallow Draw over other apps issue
<p>We have been working on "Draw over other apps" permission to develop a cool function for our app on Marshmallow.</p>

<p>Our app's new feature worked perfectly with the very first installation of our app.
We didn't have any issue with "Draw over other apps" permission.</p>

<p>However, our nightmare began when our app was erased and reinstalled or updated with a newer version. 
The new feature didn't work at all and there was no error message at all.</p>

<p>When we checked the status of "Draw over other apps" it was activated. It meant our new feature was supposed to work but it did not.</p>

<p>But once we refreshed "Draw over other apps" status from inactivated to activated even though it had already been "activated", a new feature worked again perfectly.</p>

<p>We don't think we can ask users to refresh "Draw over other apps" manually at every update or reinstallation.</p>

<p>Any help will be greatly appreciated.
Anyone?</p>

<hr>

<p>1.Activity - 2.Service(PopupWindow)</p>

<h2>3.PermissionOverlay Activity</h2>

<p>2.Service</p>

<pre><code>public void runPopup() {
    if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
        if(!Settings.canDrawOverlays(getBaseContext())) {
            setOverlayPermission();
            return;
        }
    }

    // other working..

}

public void setOverlayPermission() {

    Runnable myRunnable = new Runnable() {

        @Override 
        public void run() {

            new PermPermission(instance)
            .setPermissionListener(hecpermissionlistener)
            .setDeniedMessage("The necessary permissions!")
            .setPermissions(android.Manifest.permission.SYSTEM_ALERT_WINDOW)
            .check();

        } 
    };

    grantHandler.post(myRunnable);
 }
</code></pre>

<p>3.PermissionOverlay Activity</p>

<pre><code>public void requestPermissions(ArrayList&lt;String&gt; needPermissions) {

    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
            Uri.parse("package:" + packageName));

    startActivityForResult(intent, REQ_CODE_REQUEST_SETTING);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
        case REQ_CODE_REQUEST_SETTING:
            checkPermissions(true);

            break;
        default:
            super.onActivityResult(requestCode, resultCode, data);
    }

}
</code></pre>