从Android应用程序创建文本文件在LG-D850中不可见

时间:2017-08-16 15:42:25

标签: android lg android-internal-storage

我创建了一个Android应用程序,可以创建文本文件并在设备本地存储中写入。它在所有其他设备上运行良好,我可以在内部存储中看到创建的文件。然而在LG-D850(更新到Android版本7.1),该应用程序工作正常但不在内部存储中创建/显示文件。我检查了存储/模拟/ 0但它不在那里。

1 个答案:

答案 0 :(得分: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
    }
}