For example, I want to start Gmail in code/command line, but I don't know its main activity name.
am start -n com.google.android.gm/.XXXXX It's available through decompiling the apk, but it's difficult.
You can plug your phone into the computer and look at the DDMS log, application launches are printed there, e.g:
05-11 09:19:15.725: INFO/ActivityManager(96): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x2000000 cmp=com.google.android.gm/.ConversationListActivity bnds=[125,410][235,540] } from pid 2457 So, com.google.android.gm/.ConversationListActivity, would seem like the right choice, at least, that's what the icon seems to launch.
You don't need to know it's name, instead you should use implicit intent and specify action along with type and some extras, for example
final Intent intent = new Intent(); intent.setType("message/rfc822"); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, "Some subject"); System will search for components available to run this intent.
In continuation to the previous answers above I'd like to extend it to what helped me by combining it.
I searched the AndroidManifest.xml file for android.intent.action.MAIN (Tony the pony) and used the name attribute in the following command run on the actual device and executed the app:
$ adb logcat | grep "com.some.interesting.app" 10-23 14:53:34.795 10568 12967 W RecentsModel: getRunningTask taskInfo=TaskInfo{userId=0 taskId=286 displayId=0 isRunning=true baseIntent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.some.app/com.some.interesting.app.splash.SplashActivity } baseActivity=ComponentInfo{com.some.app/com.some.interesting.app.splash.SplashActivity} topActivity=ComponentInfo{com.some.app/com.some.interesting.app.main.MainActivity} origActivity=ComponentInfo{com.some.app/com.some.interesting.app.splash.SplashActivity} realActivity=ComponentInfo{com.some.app/com.some.interesting.app.main.MainActivity} numActivities=1 lastActiveTime=3026326848 supportsSplitScreenMultiWindow=true supportsMultiWindow=true resizeMode=2 isResizeable=true token=WCT{android.window.IWindowContainerToken$Stub$Proxy@feba6cc} topActivityType=1 pictureInPictureParams=PictureInPictureParams( aspectRatio=null sourceRectHint=null hasSetActions=false isAutoPipEnabled=false isSeamlessResizeEnabled=true) displayCutoutSafeInsets=Rect(0, 94 - 0, 0) topActivityInfo=ActivityInfo{1f05d15 com.some.interesting.app.splash.SplashActivity} launchCookies=[] positionInParent=Point(0, 0) parentTaskId=-1 isFocused=false isVisible=true topActivityInSizeCompat=false locusId= null windowMode=0} 10-23 14:53:34.958 10568 10568 D RecentsImpl: mActivityStateObserver com.some.interesting.app.main.MainActivity 10-23 14:53:34.958 10568 10568 W RecentsImpl: onResumed className=com.some.interesting.app.main.MainActivity mIsInAnotherPro=false isKeyguardLocked=false from the above output the cmp=com.some.app/com.some.interesting.app.splash.SplashActivity is actually what we're lookingn for.
So if you execute:
$ am start com.some.app/com.some.interesting.app.splash.SplashActivity or
$ am start com.some.app/com.some.interesting.app.main.MainActivity The app will execute in the device.