Search code examples
javaandroidandroid-intentstart-activityspecifier

Open android intent using a specific application(package name known)


My problem is that I have an intent such as this one.

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);     
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);        
intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);     
intent.putExtra(SearchManager.QUERY, artist);
if(intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}

And what happens is when I test the app it asks an open with. So if I open the standard music android app it doesn't open but when I use Google music it works like a charm.

So if there is no choice and I must use Google music as no could one answered this question I am guessing it is some problem I don't know. But atleast is there a way to set it such that it opens only via Google music app. Like setting googlw music as the default application to open the particular intent sent only by my application without harming any other process.

I am a beginner in Android. And pls. pls. Do help me.


Solution

  • How it works.

    I read in a particular article of stack overflow I don't know which. But but guy mention that to limit an send intent you could use intent.setClass however it requires knowing the activity name as well as the package name. But I don't know the activity name. So on a hunch I tried using intent.setPackage and Boom it worked. I would also like to thank giorashc for his efforts.