Reputation: 4205
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.
Upvotes: 16
Views: 38444
Reputation: 97
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.
Upvotes: 2
Reputation: 49
Just go to Android package n open Android Manifest File n check out this activity element
<activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</activity>
Upvotes: 4
Reputation: 551
Step1: Start "adb logcat" in command prompt.
Step2: Open the app (either in emulator or real device)
Upvotes: 6
Reputation: 41357
This can be found in the application's manifest.
The main activity is the activity
with the intent-filter
whose name is android.intent.action.MAIN
.
Upvotes: 23
Reputation: 9258
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.
Upvotes: 4
Reputation: 30168
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.
Upvotes: 8