Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how do i open another app from my app?

Tags:

I understand how to use intents and startActivity() when opening another activity within my own app, but how do you start a different app? specifically:

  • How do you determine if the user has the needed app installed on their device?
  • How do you start that app?
  • How do you pass parameters to that app?
  • How do you find all this info out for a specific app (say Adobe reader, or google maps)?
like image 611
mtmurdock Avatar asked May 27 '10 17:05

mtmurdock


People also ask

Can an Android app open another app?

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.

How do I open multiple instances of the same app on Android?

Here is how you can run multiple instances of an app using Parallel Space: Open Parallel Space and tap on the apps you want to clone. Select Add to Parallel Space. Once the apps are in the Parallel Space, tap on the one you want to run.

How do I open another app activity?

If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);


1 Answers

How to see if Intent is available:

  1. Try calling Intent and deal with ActivityNotFoundException if it isn't available

    Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  try {     startActivity(intent); }  catch (ActivityNotFoundException e) {     Toast.makeText(OpenPdf.this,          "No Application Available to View PDF",          Toast.LENGTH_SHORT).show(); } 

    or

  2. Query the Package Manager to see if it is ahead of time:

    PackageManager packageManager = getPackageManager(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType("application/pdf");  List list = packageManager.queryIntentActivities(intent,     PackageManager.MATCH_DEFAULT_ONLY);  if (list.size() > 0) {     intent.setDataAndType(path, "application/pdf");     startActivity(intent); } 

How to pass parameters to an application or know its capabilities:

  1. List of Available Intents for Google Applications
  2. List of Intents by 3rd parties @ OpenIntents
like image 152
Tim Kryger Avatar answered Sep 18 '22 17:09

Tim Kryger