Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code to launch external app explicitly

Tags:

From one of my apps, I'm trying to launch another. I want to use an explicit intent.

ComponentName cn = new ComponentName("com.myOtherApp", "OtherAppActivity"); Intent intent = new Intent(); intent.setComponent(cn); context.startActivity(intent); 

When I run that code, however, it asks if I've declared that activity in my manifest. However, when I put the following into the manifest, I get the same error:

<activity android:name="com.myOtherApp.OtherAppActivity"> </activity> 

What am I doing wrong?

Thanks

like image 445
CL22 Avatar asked May 09 '11 17:05

CL22


1 Answers

Try something like this...

In the manifest for 'myOtherApp' use an intent filter for 'OtherAppActivity' with a company specific intent, example...

<activity     android:name=".OtherAppActivity"     android:label="@string/app_name" >     <intent-filter>         <action android:name="com.mycompany.DO_SOMETHING" />     </intent-filter> </activity> 

Then, in the 'calling' app, use...

Intent intent = new Intent(); intent.setAction("com.mycompany.DO_SOMETHING"); context.startActivity(intent); 
like image 77
Squonk Avatar answered Sep 18 '22 11:09

Squonk