Execute file from Android device programatically
I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:
try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));
String sCurrentLine;
ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}
processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).
Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?
java android file
add a comment |
I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:
try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));
String sCurrentLine;
ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}
processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).
Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?
java android file
add a comment |
I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:
try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));
String sCurrentLine;
ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}
processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).
Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?
java android file
I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:
try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));
String sCurrentLine;
ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}
processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).
Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?
java android file
java android file
edited Nov 22 '18 at 0:30
DanZoe
asked Nov 21 '18 at 23:38
DanZoeDanZoe
3129
3129
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you cannot do that, simply because the SD card is being mounted with -noexec
flag.
using the internal storage with chmod +x
would be the only option available.
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. usegetFilesDir().getAbsolutePath()
and.exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is nosemanage
command available to label the file.
– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421962%2fexecute-file-from-android-device-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you cannot do that, simply because the SD card is being mounted with -noexec
flag.
using the internal storage with chmod +x
would be the only option available.
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. usegetFilesDir().getAbsolutePath()
and.exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is nosemanage
command available to label the file.
– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
add a comment |
you cannot do that, simply because the SD card is being mounted with -noexec
flag.
using the internal storage with chmod +x
would be the only option available.
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. usegetFilesDir().getAbsolutePath()
and.exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is nosemanage
command available to label the file.
– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
add a comment |
you cannot do that, simply because the SD card is being mounted with -noexec
flag.
using the internal storage with chmod +x
would be the only option available.
you cannot do that, simply because the SD card is being mounted with -noexec
flag.
using the internal storage with chmod +x
would be the only option available.
answered Nov 22 '18 at 0:15
Martin ZeitlerMartin Zeitler
15.6k33965
15.6k33965
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. usegetFilesDir().getAbsolutePath()
and.exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is nosemanage
command available to label the file.
– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
add a comment |
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. usegetFilesDir().getAbsolutePath()
and.exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is nosemanage
command available to label the file.
– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?
– DanZoe
Nov 22 '18 at 0:16
@DanZoe this is not the internal storage; just see how often you've used the word external above. use
getFilesDir().getAbsolutePath()
and .exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage
command available to label the file.– Martin Zeitler
Nov 22 '18 at 1:29
@DanZoe this is not the internal storage; just see how often you've used the word external above. use
getFilesDir().getAbsolutePath()
and .exec("chmod +x " + stockfishPath)
. while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage
command available to label the file.– Martin Zeitler
Nov 22 '18 at 1:29
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?
– DanZoe
Nov 22 '18 at 5:03
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
@DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.
– Martin Zeitler
Nov 22 '18 at 6:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421962%2fexecute-file-from-android-device-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown