The Method of Changing Read Permission in Android Internal Storage
- 2021-09-24 23:39:04
- OfStack
When developing, the mobile phone needs ROOT first, and then changes the permissions through code.
<span style="color:#330033;">public synchronized static boolean getRoot(String paramString)
{
Process process = null;
DataOutputStream os = null;
try
{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(paramString + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception localException)
{
System.out.println("@@@@root cmd error:"+localException);
//localException.printStackTrace();
return false;
}finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
System.out.println("###root cmd error:"+e);
}
}
return true;
}</span>
Attention should be paid to join permissions when referencing:
getRoot("chmod -R 777 /data/data/com.xxxxx/databases/wa.db");