For permission android.permission.SYSTEM_ALERT_WINDOW on Android Marshmallow (6.0) I use the following code:

public class GeneralActivity extends Activity { public final static int ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE = -1010101; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context Context = getBaseContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(Context)) { View APIM = getLayoutInflater().inflate(R.layout.apim, null); setContentView(APIM); Button ALLOW_BUTTON = (Button) findViewById(R.id.allow_button_apim); View.OnClickListener ALLOW_BUTTON_ACTION = new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE); } }; ALLOW_BUTTON.setOnClickListener(ALLOW_BUTTON_ACTION); } } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d("CALLED", "OnActivity Result"); } } 

When the button is pressed, a dialogue really opens in which I give the application rights and press the "back" button and this brings me back to the application, but nothing has entered the onActivityResult.

    2 answers 2

    Judging by Google it is with this permission everything is bad. A bunch of bugs and a normal solution is not for the moment. You can only try to hang the flag in the activation before running the settings, that they are requested now and the next time onResume() call onResume() check the permission again. If it is - then everything is OK - otherwise the user canceled / did not turn it on.

      Because Permission will not return to onActivityResult, but will return to onRequestPermissionsResult. redefine it and that's it