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

Creating text files from android app not visible in LG-D850

我创建了一个 android 应用程序来创建文本文件并写入设备本地存储。它在所有其他设备上工作正常,我可以在内部存储中看到创建的文件。然而在 LG-D850(已更新至 android 7.1 版)中,应用程序运行正常但内部存储中的 creating/showing 文件无法正常运行。我检查了 storage/emulated/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
    }
}