Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically launch a specific application?

Tags:

android

I want to launch a specif application.

I know how to do Intents but I want to avoid the selection menu if there are multiple apps that can handle the intent, I want to go directly to a particular app. Hope this makes sense.

like image 619
mbwasi Avatar asked Jul 27 '10 12:07

mbwasi


People also ask

How do I run one application from another application?

To take the user from one activity to another, your app must use an Intent to define your app's "intent" to do something. When you pass an Intent to the system with a method such as startActivity() , the system uses the Intent to identify and start the appropriate app component.


2 Answers

You should use the function of the package manager.

Context ctx=this; // or you can replace **'this'** with your **ActivityName.this**
try {
Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.twidroid.SendTweet");
ctx.startActivity(i);
} catch (NameNotFoundException e) {
    // TODO Auto-generated catch block
}
like image 105
Carni Avatar answered Oct 19 '22 17:10

Carni


You use the package name / class directly, for example to create a new intent to call the twidroid program you'd use the followinglink text:

 Intent intent = new Intent("com.twidroid.SendTweet");

You'd probably want to put a try/catch around for a ActivityNotFoundException for when the application is not installed.

like image 39
stealthcopter Avatar answered Oct 19 '22 17:10

stealthcopter