3

How can I call an external application from my application?

E.g: I need to call Shazam (application) from my app. I can see the package name of the application in the logcat.

will that be useful for any purpose?

God
  • 1,238
  • 2
  • 18
  • 45
Eby
  • 2,769
  • 4
  • 23
  • 30

3 Answers3

2

Specifically for Shazam, the following code works:

Intent intent = new Intent("com.shazam.android.intent.actions.START_TAGGING");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if(!context.getPackageManager().queryIntentActivities(intent, 0).isEmpty()) {
    context.startActivity(intent);
} else {
    // Shazam is not installed
}

START_TAGGING is the intent which is issued when you tap the Shazam widget.

amartynov
  • 4,125
  • 2
  • 31
  • 35
1

Create the Application's launcher intent object and say startActivity.

Gopinath
  • 12,981
  • 6
  • 36
  • 50
  • You don't need to add the external class in your manifest file. If you are sure that the application will be available and installed, then just create an Intent with the known class name and launch startActivity with the intent. This is how the home application on Android lists all installed apps and launches them when you tap on an App shortcut. – Gopinath Jan 25 '11 at 10:17
  • Class shazam = Class.forName("com.shazam.android"); Intent intent = new Intent(shaz.this,shazam.getClass()); startActivity(intent); is it like this? – Eby Jan 25 '11 at 10:57
1

You can call a third party application's activity in the following way.

final Intent shazamIntent = new Intent("com.shazam.android");                
shazamIntent .setComponent(new  ComponentName("com.shazam.android","com.shazam.android.Splash"));
startActivity(shazamIntent );

But, this is not a great way to go about it. In case the package name changes (which is a very remote possibility) or the activity name changes (Splash could change to something else) your application would break. If Shazam has an Intent which can be invoked to start listening to a song use that (not sure if they have one).

Also, do necessary check in case Shazam is not installed so that your call doesn't crash.

Codevalley
  • 4,593
  • 7
  • 42
  • 56