1

Well the title say it, but the issue is this:

I have a .sh file with a command su touch /sdcard/test.txt to see if it works. But I don't know how to include it when the user install the app. How could I add it? I thought about using something like:

su
touch /sdcard/folder/path/test.sh
vi /sdcard/folder/path/test.sh

and there create the .sh file, but I don't know how to send the esc key to be able to :wq I know how to execute the file, and yes my phone is rooted. I just need to know how to include it when the apk is installed and/or how to send the esc key to finish the vi command.

Thanks

EDIT: I created a .sh file called test.sh and I created a app which one is for root users. The test.sh file only have touch /sdcard/test.txt just to see if my java code works. I created a simple app with one button and inside that button click I have this:

test.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
                try
                {
                    Process proc = Runtime.getRuntime().exec(new String[] {"su","-c","sh ./path where .sh will be/test.sh"});
                    proc.waitFor();
                }
                catch (Exception ex)
                {
                    String TAG = null;
                    Log.i(TAG, "Doesn't work", ex);
                }
            }
        });

BUT I don't know how to or where I have to add my test.sh file so when the user install my app the file is there. I tried including

Process proc = Runtime.getRuntime().exec(new String[] {"su","-c","touch /sdcard/prueba.sh ; vi /sdcard/prubea.sh ; ****Don't know how to edit, use ESC key and :wq****});
                    proc.waitFor();

Now when I click my button the app keeps running waiting for me to end the vi command, but I don't know how to since I will have to press esc to be able to :wq... Hope this makes it clear

Rotary Heart
  • 1,899
  • 3
  • 29
  • 44

2 Answers2

1

If you are sure that you have vi installed on the phone, just look up the hex code in ascii for ESC and write that to the input buffer.

Here's a good ASCII chart cppreference.com

toadzky
  • 3,806
  • 1
  • 15
  • 26
0

It sounds like you are trying to perform an action upon installation. This How to start android service on installation suggests that that's not possible to do.

Community
  • 1
  • 1
Tom Mulcahy
  • 4,847
  • 1
  • 13
  • 5
  • Not that way. I want that file to be added so I can execute it. Here's an example, I downloaded a apk called Hot reboot, and in the /data/data/com......quick_reboot/ there's a folder called files and inside it there's a .sh file that the apk run to reboot the phone. How could I do this? – Rotary Heart Oct 04 '12 at 21:06
  • I don't understand what you are doing. Are you running these commands in "adb shell"? vi and esc has just worked for me without problem. You shouldn't even need the touch command. – Tom Mulcahy Oct 04 '12 at 21:23