2

I'm trying to write an App that starts the Android STK Activity as follows:

            Intent intent = new Intent(); 
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
            intent.addCategory(Intent.CATEGORY_LAUNCHER); 
            intent.setAction(Intent.ACTION_MAIN); 
            intent.setComponent(new ComponentName("com.android.stk", "com.android.stk.StkLauncherActivity")); 
            startActivity(intent);

I keep getting the following error:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.stk/com.android.stk.StkLauncherActivity}; have you declared this activity in your AndroidManifest.xml?

I've declared the following in my manifest:

<activity android:name="com.android.stk.StkLauncherActivity"/>
Yusufk
  • 1,055
  • 2
  • 10
  • 15
  • just compare: `intent.setComponent(new ComponentName("com.android.stk", "com.android.stk.StkLauncherActivity"));` and `... {com.android.stk/com.android.stk2.StkLauncherActivity}...` ... do you see **stk2** because i see... – Selvin Dec 06 '12 at 16:54
  • Yes, that was a typo here, stk doesn't work either. – Yusufk Dec 06 '12 at 17:29

4 Answers4

4

try using PackageManager.getLaunchIntentForPackage which return an intent to launch a front-door activity in given package :

   PackageManager manager = getPackageManager(); 
   Intent intent =manager.getLaunchIntentForPackage("com.android.stk"); 
   if (intent != null)  
    startActivity(intent); 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • try it i'm sure this will work if you are passing correct PackageName – ρяσѕρєя K Dec 06 '12 at 17:15
  • The intent is null... I'm pretty sure that the PackageName is correct. – Yusufk Dec 06 '12 at 17:33
  • 1
    @Yusufk then see here when it's returning NULL http://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage%28java.lang.String%29 – ρяσѕρєя K Dec 06 '12 at 17:37
  • Ok, looks like the package did not intend a front-door launch. Any ideas on how to do a back-door launch? – Yusufk Dec 06 '12 at 17:41
  • @Yusufk : see here http://code.google.com/codesearch#oOy_5JrVRNM/trunk/packages/apps/Stk/AndroidManifest.xml&type=cs `StkLauncherActivity` Activity declared with `android:enabled="false"` means component are disabled – ρяσѕρєя K Dec 06 '12 at 17:47
  • 1
    @Yusufk : but this application have other activities like `StkSettings`,`StkMenuActivity` and `StkInputActivity` you ca try these activities to lauch but `StkLauncherActivity` is not enabled for third party application – ρяσѕρєя K Dec 06 '12 at 17:51
  • 1
    Yes, I tried these, and they do behave better, but it does not launch the STK menu, which is what I've been trying to do. Thanks! – Yusufk Dec 06 '12 at 17:54
  • @Yusufk : were you able to find a solution to open com.android.stk from your app? – nous Nov 30 '15 at 10:35
  • @Anuj Sharma: if you were successful opening sim toolkit can you explain how you did it? – nous Nov 30 '15 at 10:36
  • @nous - It was so long ago, I can't even remember this question or why I needed to do this. Something tells me I didn't get this to work though. – Yusufk Dec 08 '15 at 09:41
1

Looks like a typo on your side

com.android.stk/com.android.stk2.StkLauncherActivity

stk or stk2? :)

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
0

To launch an activity from another app,you can set "action" in the activity intent filter of android manifest of app in which your activity belong.And while launching set the same "action"to the intent

Nargis
  • 4,687
  • 1
  • 28
  • 45
  • Do you have an example of how this would look? – Yusufk Dec 06 '12 at 17:31
  • For example in the Avtivity to be called ,set Intent filter in Android Manifest as And now while startingActivity through Intent ,set action of Intent as "com.example.nargis.action.MYACTIVITY",this should work – Nargis Dec 07 '12 at 06:00
0

Try this below code snippet

final Intent intent = new Intent(Intent.ACTION_MAIN, null);

intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.abc.xyz", "com.abc.xyz.MainActivity");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23