How can I make my plugin detect if a certain theme is active?

Use get_stylesheet() to get the directory name of the theme being used. If a child theme is being used you can determine the parent with get_template().

At the top of the plugin file you can simply return early if the value is not what you want.

if ( 'my-theme' !== get_stylesheet() ) {
    return;
}