How to read or write file as getExternalStorageDirectory is deprecated in API 29?

后端 未结 3 1514
谎友^
谎友^ 2020-12-11 01:48

I am learning android development and i am facing some problem to read getExternalStorageDirectory in java, I have read https://developer.android.com/reference/android/os/En

3条回答
  •  离开以前
    2020-12-11 02:01

    Use getExternalFilesDir(), getExternalCacheDir(), or getExternalMediaDirs() (methods on Context) instead of Environment.getExternalStorageDirectory()

    String root = mContext.getExternalFilesDir(null).getAbsolutePath();
    File myDir = new File(root + "/" + mContext.getResources().getString(R.string.app_name) + "_share");
        myDir.mkdirs();
    
        
        
    

提交回复
热议问题