访问权限以在Android Studio(Huawei P20)中读取“ / sys / class / power_supply / Battery / current_now”

时间:2018-08-23 06:43:16

标签: android file-permissions battery

每个人。我试图访问文件“ / sys / class / power_supply / Battery / current_now”以获取Huawei P20中的电池电流。

f =  File("/sys/class/power_supply/Battery/current_now");
if (f.exists()) {
  return OneLineReader.getValue(f, true)

但是我得到

的错误

java.io.FileNotFoundException:/ sys / class / power_supply / Battery / current_now:打开失败:EACCES(权限被拒绝)

我已经授予读写存储的权限。

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
        )
    }
}

有人暗示这个问题吗?

1 个答案:

答案 0 :(得分:0)

您需要关闭selinux。 使用post(...items),然后您就可以从您的应用中读取它了