Do you want your Android phone to automatically launch your favorite music or podcast app when you plug in your headphones? If so, you have two easy ways to set that up, for both wired and wireless headphones.
Let MacroDroid Open Your Favorite App When Headphones Are Plugged In
MacroDroid is a free app (paid version available) that allows you to automate many tasks on your Android phone. You can use this app to set up a macro that opens your favorite app when you connect your headphones to your phone. The app’s free version is good enough for this macro.
To start, launch the Google Play Store on your phone and download and install the MacroDroid app. Launch the app and go through the welcome screens. On the app’s main interface, choose “Add Macro.” In the Triggers section, tap the “+” (plus) sign to add a new trigger.
On the following page, choose “Connectivity.” If yours are Bluetooth headphones, select “Bluetooth Event,” choose “Device Connected,” and select your paired headphones. If yours are wired headphones, choose “Headphones Insert/Remove,” select “Headphones Inserted,” and choose “No Microphone” or “With Microphone.”
In the Actions section, tap the “+” (plus) sign to add a new action. Select “Applications” and choose “Launch Application.” Give the app the required permission. Select “Launch Application” again, tap “Select Application,” and choose the app you want MacroDroid to launch.
If you don’t want the app to automatically launch during certain situations, in the Constraints section, tap the “+” (plus) sign and add those situations.
Back on the main screen, at the top, tap the “Enter Macro Name” field. Type a name for your macro, something like Launch YouTube Music. The app will now run your macro and launch your chosen app when you plug in your headphones.

Related
How to Automatically Open a Music App When Connected to Bluetooth on a Samsung Phone
Stop wasting time finding the music app.
In the future, to turn off this automation, open MacroDroid and access the “Macros” tab. Turn off the toggle for your specific macro to disable it. To remove the macro for good, tap and hold on it and choose “Delete.”
Use Tasker to Automate Launching an App When You Connect Your Headphones
Tasker is another automation app you can use to perform tasks on your Android phone. This one is slightly more complex to use than MacroDroid but offers advanced automations.

Related
Tasker is a paid app on the official Google Play Store. However, you can download Tasker’s trial version from its official website. Once you’ve installed the app either way, launch it.
Give the app the required permissions. On the main interface, in the Profiles tab, choose the “+” (plus) sign and tap “State.” If yours are wired headphones, select Hardware > Headset Plugged. If yours are wireless headphones, choose Net > BT Connected, and type the name of your headphones.
Tasker will prompt you to add a task, so tap the “New Task” prompt. Type a name for the task, such as Open YouTube, and tap the checkmark icon. On the following page, tap the “+” (plus) sign and choose App > Launch App. Select the app you want Tasker to launch when you plug in your headphones.
You’re done. Tasker will now automatically launch your chosen app when you connect your headphones to your Android device.
What to Do if Your Chosen App Doesn’t Launch?
If the app you’ve chosen doesn’t launch when you plug in your headphones, the following troubleshooting tips will help you.
Make Sure You’ve Typed the Correct Headphone Name
If you’re using wireless headphones, ensure you’ve typed the correct and exact name of your headphones in the automation apps. If there are typos in the name, fix them and re-run the automation.
Turn Off Battery Optimization for Your Automation App
Android’s built-in battery optimization feature may restrict your automation app’s functionality. As a result, your automations may sometimes not work. In this case, disable battery optimization for your app.
To do that, on your phone, head into Settings > Apps > See All Apps. Select MacroDroid or Tasker and tap “App Battery Usage.” Choose “Allow Background Usage” and turn on “Unrestricted.”
That allows your automation app to function without any restrictions.
And that’s how you can get your Android phone to automatically launch an app for you as soon as you plug in your headphones. While you’re at it, consider other tasks you can automate on Android.