I am trying to run a shell script through an android app. The script has a command which just runs a jar on the device. When I run this command directly on the shell using adb, everything works fine. But when I run it through the script using the android app, I get a permission denied exception (open failed: EACCES (Permission denied)) for the files created in /data/local/tmp folder. Can anyone guide in how to resolve this issue?
This is what my manifest looks like
<manifest ….>
<uses-sdk …>
<uses-permission… .>
…
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
…
<application …>
…
</application>
</manifest>
Thanks.
You can use the adb interface to copy and/or push files to the
/data/local/tmp
folder but if you want to use/see them in the terminal app you will need to (in adb interface) firstthen make a folder inside the folder. Example
next change the permissions
Now you have a folder you can read and write to.
A few things that I would like to know is how to make the system think that the
su
binary is in the/system/bin
folder (without copying) because I can only get tmp... root access because even with root access, I can not remount the system directory asrw
because the zte-paragon has its system partition formatted as a read-only file-systemIf I understand the scenario correctly, you create the script on the fly, and use
/data/local/tmp
as an easy location that is both publicly writable and executable. Once, this was possible. But on recent versions of Android, security has been tightened.Your app can execute files under
/data/data/${your.package}
. You can use getContext().getFilesDir() to reliably obtain the full path. Note that you still need to usechmod 500
to ensure that the file has executable permission.If you have some fixed executables (binaries or scripts) that must be installed with your app, there is a clever trick to let the system package installer take care of all that for you: make sure the file has a name "libsomething.so" and put it in
/libs/armeabi
directory under the Eclipse project root. After installation, the files will be present in getContext().getApplicationInfo().nativeLibraryDir directory with executable permissions set.PS You don't need the WRITE_EXTERNAL_STORAGE permission for this to work (maybe you need it for other things your app does).
PPS You can run a shell script from anywhere, including
/sdcard
, and you don't need executable permission for the script. Instead, usesh -c source full.path.to.script
.Make sure the
/data/local/tmp
location is world-executable on your device:If it's not, there's nothing you can do, and you need to use the standard storage (internal
/data/data/{package}
or external/sdcard/
).Make sure you made the file world-readable.
You don't need any permissions.
I think the reason is that your Andorid is not been rooted. the "/data" have the root Permission. So root your phone first, and give your app the permission. you can try command:"su" int the shell change to root.