Android 更改应用程序中的文件权限
我尝试更改应用程序中的文件权限。代码如下:Android 更改应用程序中的文件权限,android,shell,Android,Shell,我尝试更改应用程序中的文件权限。代码如下: Runtime.getRuntime().exec("chmod 777 /sdcard/test.txt"); 此代码在我的应用程序中不起作用,但没有错误日志。 我还检查了/system/bin下的shell工具,发现chmod在/system/bin下,但其他一些信息显示chmod>toolbox。我对此不清楚。我的应用程序使用了android:sharedUserId=“android.uid.system”。 如何运行此代码或如何更改文件的权
Runtime.getRuntime().exec("chmod 777 /sdcard/test.txt");
此代码在我的应用程序中不起作用,但没有错误日志。
我还检查了/system/bin下的shell工具,发现chmod在/system/bin下,但其他一些信息显示chmod>toolbox。我对此不清楚。我的应用程序使用了android:sharedUserId=“android.uid.system”。
如何运行此代码或如何更改文件的权限?非常感谢 您在测试中使用了路径
/sdcard/
——您的SD卡是否使用支持标准Unix权限的文件系统格式化?(没有。)
您没有在字符串中给出chmod(1)
的显式路径——您确定chmod(1)
是:
- 在您的设备上可用
- 可用于当前的
路径
环境变量设置
Runtime rt = Runtime.getRuntime();
Process proc;
try {
proc = rt.exec(new String[] { "su", "-c", "chmod 777 " + Constants.filename });
proc.waitFor();
} catch (Exception e){ //DOSTUFFS }
这应该可以解决问题您的手机是否有根?我的猜测是,没有root用户就不能使用这些敏感命令。我之前添加了Runtime.getRuntime().exec(“su”),但它不起作用。以
$su
#chmod 777/sdcard/test.txt运行命令,可以更改权限。因此,我认为文件路径是正确的。请尝试将字符串更改为“su-c\”chmod 777/sdcard/test.txt\”