Hide/show a custom block I have created a custom block of id downloadourapp and I would like to show/hide it base on certain statements.

I have create my custom module along with .module file where the code should be, however, I failed to find the right function to be used for that matter.

is hook_block_view_alter is the right function and how to hide or show this downloadourapp specific block.
Plugin ID doesn't equal Block ID, example. 

isForbidden is not a static function, need to use forbidden.

if ($block-&gt;id() == 'downloadourapp') {

    // If the user's phone is Android.
    if(preg_match("/(android)/i", $_SERVER["HTTP_USER_AGENT"])) {

    return AccessResult::forbidden()-&gt;addCacheableDependency($block);

    }
}