Im trying to make an app that automatically launches the music player of your choice when the headphones are plugged in. For this to work, when the user plugs in their headphones I want an intent to show all the applications on their phone so they can click there default music player such as rhapsody, spotify, etc. Since everybody has different music apps. I can't use an intent to launch just the package name because it might not be the same for everybody. Is there an intent to show all applications so the user can pick their default one. Thanks.
Another way i was thinking would be to search the specific third party app in a list view on the phone and then set it as default.
code I am trying to use, code needs to work inside case1
private class MusicIntentReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
Log.d(TAG, "Headset is unplugged");
break;
case 1:
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
break;
default:
Log.d(TAG, "I have no idea what the headset state is");
}
}
}
}