views:

552

answers:

3

Hey guys,

I have a question related to choosing an application programmatically when shown the dialog "Complete Action Using" in Android.

An example would be as follow: In my code, I have this statement

startActivity(new Intent(Intent.ACTION_VIEW,
        Uri.parse("http://www.youtube.com/watch?v=98yl260nMEA")));

I will then shown a dialog box with two options: to complete the action using the Browser or YouTube

Any idea how can I choose YouTube without being shown the dialog box?

Thanks!

Nicholas

A: 

I think you will need more information about the intent-filter of the app you want to launch by default (in this case youtube app). That target app might have multiple intent-filters and one of them might be more specific. You can call startActivity with that specific intent, and then the intended app will be launched directly. However, this requires you to have more knowledge of the target app (which is difficult in most cases like Youtube app).

Other than that, I don't think you can do much from within your app. Intent resolution is done by the Android framework, so if a user app could override it somehow, that would be a flaw in terms of security.

Jayesh
hmm ... makes some sense. thanks, Jayesh. I have this code (but it only shows me the suggested apps to use - in this case, the Browser and YouTube)PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse(http://www.youtube.com/watch?v=Zi_XLOBDo_Y)), 0); Iterator<ResolveInfo> actList = activities.iterator(); while(actList.hasNext()) { ResolveInfo curr = actList.next(); Log.d("Intents =====> ", curr.toString() + " " + curr.match + " " + curr.isDefault); }
Nicholas Key
A: 

This thread seems relevant to your question: android-youtube-app-play-video-intent

Leonid
A: 
PackageManager pm = getPackageManager(); 
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse(youtube.com/watch?v=Zi_XLOBDo_Y)), 0); 
Iterator<ResolveInfo> actList = activities.iterator(); 
while(actList.hasNext()) { 
   ResolveInfo curr = actList.next(); 
   Log.d("Intents =====> ", curr.toString() + " " + curr.match + " " + curr.isDefault); 
}
Nicholas Key