裏技的ですが、以下のexecメソッドを使って
exec("/system/bin/chmod", "744", "/data/data/net.gimite.nativeexe/a.out");
とすることでパーミッションを744にすることができたので、この方法でいけるかもしれません。
// Executes UNIX command.
private String exec(String arg0, String arg1, String arg2) {
try {
// android.os.Exec is not included in android.jar so we
need to use reflection.
Class<?> execClass = Class.forName("android.os.Exec");
Method createSubprocess = execClass.getMethod("createSubprocess",
String.class, String.class, String.class, int[].class);
Method waitFor = execClass.getMethod("waitFor", int.class);
// Executes the command.
// NOTE: createSubprocess() is asynchronous.
int[] pid = new int[1];
FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(
null, arg0, arg1, arg2, pid);
// Reads stdout.
// NOTE: You can write to stdin of the command using new
FileOutputStream(fd).
FileInputStream in = new FileInputStream(fd);
BufferedReader reader = new BufferedReader(new
InputStreamReader(in));
String output = "";
try {
String line;
while ((line = reader.readLine()) != null) {
output += line + "\n";
}
} catch (IOException e) {
// It seems IOException is thrown when it reaches EOF.
}
// Waits for the command to finish.
waitFor.invoke(null, pid[0]);
return output;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
} catch (SecurityException e) {
throw new RuntimeException(e.getMessage());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalArgumentException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage());
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getMessage());
}
}
ref.
http://gimite.net/en/index.php?Run%20native%20executable%20in%20Android%20App
2009/07/03 12:21 に zhangho<
cui.ch...@gmail.com> さんは書きました:
>
>> android.Context.openFileOutputを使うと、modeに MODE_WORLD_READABLEを指定する事で全ての他
>
> ありがとうございます。
> Context.openFileOutputは基本的に/data/data/<package>/files の直下しか作成できないですね。
> たとえば/data/data/<package>/wwwとかにコピーしようとする場合はFileOutputStreamでするしかないですが
>
> sdcardの画像をにFileOutputStreamでコピーしたら
> パーミッションが -rw-----になっています。
>
> さらに下記の方法でパーミッションを与えても画像が開けない。
> intent.setAction(Intent.ACTION_VIEW);
> intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
> intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
> intent.setDataAndType(Uri.fromFile(f), filetype);
> startActivity(intent);
>
> 手動でパーミッションを -rw-----から---rw-rw-に変更したら開けました。
>
> FLAG_GRANT_READ_URI_PERMISSIONも駄目なのでなにかいい方法が無いでしょうか?
>
>
> >
>