You can use a try catch to catch the exception and display a Alert Dialog?
**Note: i changed your method name
private void pickAudioIntent() {
try{
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_AUDIO_REQUEST);
}catch(Exception e){
//No activity? Display alert Dialog to user
}
You can also check before hand if any activity can handle the intent by doing the below
public static boolean isIntentAvailable(Intent intent) {
final PackageManager mgr = mContext.getPackageManager();
List<ResolveInfo> list =
mgr.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
That would change the pickAudioIntent() to :
private void pickAudioIntent() {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
if(isIntentAvailable(i)){
startActivityForResult(i, PICK_AUDIO_REQUEST);
return;
}
//Show Dialog to user as no intent available
}