Open external Android app from within Android app

You can open any external Android application from within your Android application by pressing a button (or any other event). All you need to know is the namespace of the application you want to launch.

For this functionality use following code snippet:

public class MainActivity extends Activity {</p>
<p>private Button openAppButton;</p>
<p>@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.activity_main);</p>
<p>openAppButton = (Button) findViewById(R.id.openApp);<br />
openAppButton.setOnClickListener(new OnClickListener() {</p>
<p>@Override<br />
public void onClick(View arg0) {</p>
<p>Intent i = new Intent();<br />
PackageManager manager = getPackageManager();<br />
i = manager.getLaunchIntentForPackage("launching.app.namespace");<br />
i.addCategory(Intent.CATEGORY_LAUNCHER);<br />
startActivity(i);<br />
}</p>
<p>});<br />
}</p>
<p>}<br />

In this code replace „launching.app.namespace“ with the namespace of the app you want to launch. If you don’t know the namespace of the app you can go to Google Play and search for the app. Inside the URL the namespace is mentioned as the „id“. For example, Google Maps has following URL:

 https://play.google.com/store/apps/details?id=com.google.android.apps.maps

As you can see, the value of id is „com.google.android.apps.maps“ – this is the app’s namespace.

 

About Dominik
Currently working as an Android/iOS developer for Cineman, Switzerland. Owner of http://www.ukon.ch and https://play.google.com/store/apps/details?id=com.cheatdatabase

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.