sPFApp/src/main/java/it/polimi/spf/app/PopupAppRegistrationHandler.java
@Override
    public void handleRegistrationRequest(Context context, AppDescriptor descriptor, final Callback callback) {
        final DialogView dialogView = new DialogView(context, descriptor);

        Dialog dialog = new AlertDialog.Builder(context).setPositiveButton(R.string.app_permission_dialog_allow, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                callback.onRequestAccepted(dialogView.getSelectedPersona());
            }
        }).setNegativeButton(R.string.app_permission_dialog_deny, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                callback.onRequestRefused();
            }
        }).setView(dialogView.getView()).create();


        /*
         * Workaround to fix the crash:
		 * android.view.WindowManager$BadTokenException: Unable to add window
		 * android.view.ViewRootImpl$W@3d67307 -- permission denied for this window type
		 * that appears only on Android 6.0 Marshmallow or greater.
		 * Start a dialog fragment to explain the procedure to the user.
		 * When the user accepts, onClickOnUnderstoodButton() will be called.
		 */
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //if android MarshMallow or greater
            if (Settings.canDrawOverlays(context)) {
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                dialog.show();
            } else {
                //to prevent a crash
                Toast.makeText(context, "You must activate SPF!", Toast.LENGTH_SHORT).show();
            }
        } else {
            //other older Android's versions
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            dialog.show();
        }
    }
@Override
    public void handleRegistrationRequest(Context context, AppDescriptor descriptor, final Callback callback) {
        final DialogView dialogView = new DialogView(context, descriptor);

        Dialog dialog = new AlertDialog.Builder(context).setPositiveButton(R.string.app_permission_dialog_allow, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                callback.onRequestAccepted(dialogView.getSelectedPersona());
            }
        }).setNegativeButton(R.string.app_permission_dialog_deny, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                callback.onRequestRefused();
            }
        }).setView(dialogView.getView()).create();


        /*
         * Workaround to fix the crash:
		 * android.view.WindowManager$BadTokenException: Unable to add window
		 * android.view.ViewRootImpl$W@3d67307 -- permission denied for this window type
		 * that appears only on Android 6.0 Marshmallow or greater.
		 * Start a dialog fragment to explain the procedure to the user.
		 * When the user accepts, onClickOnUnderstoodButton() will be called.
		 */
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //if android MarshMallow or greater
            if (Settings.canDrawOverlays(context)) {
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                dialog.show();
            } else {
                //to prevent a crash
                Toast.makeText(context, "You must activate SPF!", Toast.LENGTH_SHORT).show();
            }
        } else {
            //other older Android's versions
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            dialog.show();
        }
    }
@ Override public void handleRegistrationRequest ( Context context , AppDescriptor descriptor , final Callback callback ) { final DialogView dialogView = new DialogView ( context , descriptor ) ; Dialog dialog = new AlertDialog . Builder ( context ) . setPositiveButton ( R . string . app_permission_dialog_allow , new AlertDialog . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { callback . onRequestAccepted ( dialogView . getSelectedPersona ( ) ) ; } } ) . setNegativeButton ( R . string . app_permission_dialog_deny , new AlertDialog . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { callback . onRequestRefused ( ) ; } } ) . setView ( dialogView . getView ( ) ) . create ( ) ; /*
         * Workaround to fix the crash:
		 * android.view.WindowManager$BadTokenException: Unable to add window
		 * android.view.ViewRootImpl$W@3d67307 -- permission denied for this window type
		 * that appears only on Android 6.0 Marshmallow or greater.
		 * Start a dialog fragment to explain the procedure to the user.
		 * When the user accepts, onClickOnUnderstoodButton() will be called.
		 */ if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) { //if android MarshMallow or greater if ( Settings . canDrawOverlays ( context ) ) { dialog . getWindow ( ) . setType ( WindowManager . LayoutParams . TYPE_SYSTEM_ALERT ) ; dialog . show ( ) ; } else { //to prevent a crash Toast . makeText ( context , "You must activate SPF!" , Toast . LENGTH_SHORT ) . show ( ) ; } } else { //other older Android's versions dialog . getWindow ( ) . setType ( WindowManager . LayoutParams . TYPE_SYSTEM_ALERT ) ; dialog . show ( ) ; } }
/*
(non-Javadoc)

@see it.polimi.spf.framework.security.AppRegistrationHandler#
handleRegistrationRequest(android.content.Context,
it.polimi.spf.shared.model.AppDescriptor,
it.polimi.spf.framework.security.AppRegistrationHandler.Callback)
/ * ( non - Javadoc )