everyone. I tried to access file "/sys/class/power_supply/Battery/current_now" to retrieve the battery current in Huawei P20.
f = File("/sys/class/power_supply/Battery/current_now");
if (f.exists()) {
return OneLineReader.getValue(f, true)
However i get the error of
java.io.FileNotFoundException: /sys/class/power_supply/Battery/current_now: open failed: EACCES (Permission denied)
i already grant permission of read and write to storage.
private val PERMISSIONS_STORAGE = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
fun verifyStoragePermissions(activity: Activity) {
// Check if we have write permission
val permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
)
}
}
Anyone has the hint for this problem?