9

I have the following in my AndroidManifest.xml (I just added a second activity to the default project):

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
    android:name="com.example.com.testapp.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>
<activity
    android:name="com.example.com.testapp.TestActivity"
    android:label="@string/title_activity_test" >
    <intent-filter>
        <action android:name="com.testapp.action.TEST_ACTION" />
    </intent-filter>
</activity>

I want to launch the TestActivity using adb command. I tried:

./adb shell am start -a com.testapp.action.TEST_ACTION

But it gives the error:

 Error: Activity not started, unable to resolve Intent { act=com.testapp.action.TEST_ACTION flg=0x10000000 }

Can someone please explain why I am getting this error and how to resolve it?

Edit :

Can anyone tell a way to just use action to launch the 'TestActivity'.

Jake
  • 16,329
  • 50
  • 126
  • 202

4 Answers4

6

I think you should add the code below into your intentfilter

<category android:name="android.intent.category.DEFAULT"/>
陈薛星
  • 76
  • 1
  • 3
5

try using: adb shell "am start -n com.example.com.testapp/.TestActivity -a com.testapp.action.TEST_ACTION"

or

adb shell "am start com.example.com.testapp -a com.testapp.action.TEST_ACTION"

hope that works.

The Badak
  • 2,010
  • 2
  • 16
  • 28
2

Try adb shell am start -n com.mypackage.name/com.mypackage.name.TEST_ACTION (replace the package names and activity names as needed)

Take a look at this solution.

Community
  • 1
  • 1
FMontano
  • 907
  • 8
  • 17
0

To expand on what 陈薛星 wrote, in the "Android developer guide on Intent Filters" under "Category Test", it states

Note: Android automatically applies the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult(). If you want your activity to receive implicit intents, it must include a category for "android.intent.category.DEFAULT" in its intent filters, as shown in the previous example.

So you need to add <category android:name="android.intent.category.DEFAULT"/> to your intent filter.

This will match an implicit intent. (Several other answers show how to target a class explicity).

Hod
  • 2,236
  • 1
  • 14
  • 22