I am working on an app and i have to read a package name from /data/data folder in rooted device. I have tried following code but not able to read that file. Please help me. I am using google pixel 4 with android 13
val arr = arrayOf(
"su",
"chmod 777 /",
"chmod 777 " + Environment.getDataDirectory(),
"chmod 777 " +Environment.getDataDirectory()+ "/data/",
"chmod 777 " +Environment.getDataDirectory()+ "/data/com.packagename"
)
try {
val process = Runtime.getRuntime().exec("su")
val out = DataOutputStream(process.outputStream)
for (str in arr) out.writeBytes(
"""
$str
""".trimIndent()
)
out.writeBytes("exit\n")
out.flush()
val proc = process.waitFor()
Log.d("MYAPPINFOTA", proc.toString())
// Log.d("MYAPPINFOTA", file.listFiles().size.toString())
} catch (e: Exception) {
e.printStackTrace()
}
Process return 1 and Say file not exist
Thanks in advance
if you only need to read files avoid using cdmod 777 use cdmod 755 for read only
try the following