I tore my hair out over this one too. Your code only works if the user has granted an extended permission for that which is not ideal.
Lee mas