现在的位置: 首页 > 综合 > 正文

android中获得相对高的权限方法

2013年12月12日 ⁄ 综合 ⁄ 共 1193字 ⁄ 字号 评论关闭

openFileOutput方法:

FileOutputStream fos;
fos = openFileOutput("filename", MODE_WORLD_READABLE);
FileOutputStream fos;
fos = openFileOutput("filename", MODE_WORLD_READABLE);

可用的mode 参数如下:

/**
* File creation mode: the default mode, where the created file can only
* be accessed by the calling application (or all applications sharing the
* same user ID).
* @see #MODE_WORLD_READABLE
* @see #MODE_WORLD_WRITEABLE
*/
public static final int MODE_PRIVATE = 0x0000;
/**
* File creation mode: allow all other applications to have read access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_WRITEABLE
*/
public static final int MODE_WORLD_READABLE = 0x0001;
/**
* File creation mode: allow all other applications to have write access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_READABLE
*/
public static final int MODE_WORLD_WRITEABLE = 0x0002;
/**
* File creation mode: for use with {@link #openFileOutput}, if the file
* already exists then write data to the end of the existing file
* instead of erasing it.
* @see #openFileOutput
*/
public static final int MODE_APPEND = 0x8000;

其实该方法最终还是调用了系统的chmod来实现的改变文件权限的功能。

但是该方法有局限性,他创建的文件只能位于该程序的私有目录下,即/data/data/app-package/files/

Runtime.getRuntime().exec()方法

Process p = Runtime.getRuntime().exec("chmod 644 " + filename);
int status = p.waitFor();
if (status == 0) {
   //chmod succeed
} else {
    //chmod failed
}

抱歉!评论已关闭.