Sign up ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I'm trying to open a text file from within a terminal window emulator -- but not so it opens in the actual terminal but more like I've just clicked on it.

So my question is: What command can I use to open /mnt/sdcard/textfile.txt from a terminal window emulator from ROM Toolbox Lite within the Android GUI so that it will open with any one of my text editing applications? Will I need to run su before I can run what ever command? I'd prefer not to, but the device is rooted so I can run su.

Im using Android version 4.0.4

share|improve this question
Do you want to open it in a seperate program? Or do you just want to quickely edit it? nano or vi are usually available on *nix based systems. I prefer nano because it is a bit cleaner imho. – John Apr 20 '13 at 23:40
No i want the command to open the file with droid edit or with es text editor – Richard Lalaz Apr 21 '13 at 0:26
Thank you for your input but i am looking for something simpler than that... I realized last night all i want to know is how to do this like in windows if you type in C:\text.txt from command prompt it will load the default text editor (what ever that may be) so how do i do it using bash terminal emulator from ROM Toolbox Lite? – Richard Lalaz Apr 21 '13 at 19:48
You can always just rip the file off of the phone using adb and then open it on your computer – John Apr 22 '13 at 12:05

2 Answers 2

Launching apps in Android isn't straightforward. You'll have to use am start combined with certain <PARAMS> to launch the app or a particular section of it.

From the comments, it seems that you may want to launch the text file using ES Note Editor. In that case, first identify the activity responsible for the edit window you see when the file is opened in the editor using GUI.

Note: Tested the solution on Android 4.2, 4.4 and 5.0.


  1. Open the file manually in the editor using GUI, and make sure that it stays active on the screen.
  2. Connect your phone into PC in debugging mode, setup ADB on PC, and enter into PC's terminal/cmd the commands:

    adb shell
    dumpsys activity | grep mFocusedActivity

    The output may look like:

    mFocusedActivity: ActivityRecord{42839028 u0}

    The relevant info (activity) is .app.editor.PopNoteEditor and package name is You may use the command dumpsys activity to see some more useful stuff.

    That's just for brief understanding. Keep the whole string ( ready to be used.

  3. You may close the editor on Android. Open your favorite terminal app in Android and enter:

    am start -n <PACKAGE_NAME/ACTIVITY> -d <FILEPATH> --activity-clear-task
    • -n will allow to launch the app's mentioned component.
    • <PACKAGE_NAME/ACTIVITY> is the string we noted in step 2. For ES Note Editor it would be
    • -d is to allow data to be passed to the app's activity.
    • <FILEPATH> is the location of the text file you want to open.
    • --activity-clear-task will make sure that the activity is not launched from "Recents" but from scratch.

    (Enter am start to dive deeper into interesting stuff.)

    In my case, the final query for file aero.txt under /sdcard/airdroid/ looked like:

    am start -n -d file:///sdcard/airdroid/aero.txt --activity-clear-task

    The file opened successfully.

  4. I use QuickEdit Text Editor as default text editor and the relevant query looked like:

    am start -n com.rhmsoft.edit/.activity.MainActivity -d file:///sdcard/airdroid/nmon.txt --activity-clear-task

Have fun!

share|improve this answer
When you "Connect your phone into PC in debugging mode, setup ADB on PC", do you actually send commands to the phone via PC? – JasonStack Nov 8 at 18:28
Yes. That's true. – Firelord Nov 9 at 0:21

In addition to this answer you can use the following solution which is taken from rohitverma's answer here and noticed in Lucky's comment.

  1. am start -a android.intent.action.VIEW -d <FILEPATH> -t text/plain --activity-clear-task      

    It will execute activity of android system with all candidates registered for "plain text" available for selection in a dialog.

    For my file, the query was and dialog shown were:

    am start -a android.intent.action.VIEW -d file:///sdcard/airdroid/ -t text/plain --activity-clear-task

                                                                IMG: dialog.

  1. You may use input keyevent <KEYCODE/KEYNAME> command to select the app in the dialog. Input events list is available here by LionCoder.

    Relevant keyevents are:

    19 -->  "KEYCODE_DPAD_UP" 
    20 -->  "KEYCODE_DPAD_DOWN" 
    21 -->  "KEYCODE_DPAD_LEFT" 
    22 -->  "KEYCODE_DPAD_RIGHT"

    And the usage would be like:

    input keyevent 20


    input keyevent KEYCODE_DPAD_DOWN 

    Use the combination of them to achieve the goal, and use 66 --> "KEYCODE_ENTER to simulate "enter".

I would still go for this answer if needed. :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.