0

我创建了一个创建文本文件并写入设备本地存储的 android 应用程序。它在所有其他设备上工作正常,我可以在内部存储中看到创建的文件。但是在 LG-D850(更新到 android 版本 7.1)中,应用程序运行良好,但无法在内部存储中创建/显示文件。我已经检查了 storage/emulated/0 但它不存在。

4

1 回答 1

0

解决方案

尝试在您的创建中使用此调用此方法并接受许可,您应该能够看到您放置它的文本文件。

public  boolean isStoragePermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
            == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
        } else {

            Log.v(TAG,"Permission is revoked");
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
            return false;
        }
    }
    else { //permission is automatically granted on sdk<23 upon installation
        Log.v(TAG,"Permission is granted");
        return true;
    }
}

检查用户单击的内容并在他们选择后决定如何处理应用程序的方法。

@Override
public void onRequestPermissionsResult(int requestCode,
                                   String permissions[], int[] grantResults) {
switch (requestCode) {
    case 1: {

      // If request is cancelled, the result arrays are empty.
      if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.          
        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.
            Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
        }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}
于 2017-08-16T15:59:47.757 回答