How to create a folder in the phone memory (not SD card) in Android?

徘徊边缘 提交于 2021-01-27 23:31:56

问题


I tried the following code to implement what I need

File direct = new File(Environment.getRootDirectory() + "/YourFolder");

if (!direct.exists()) {
  if (direct.mkdir()) {
    Toast.makeText(getApplicationContext(), "Yes make directory", Toast.LENGTH_LONG).show();
  }
  else
  {
    Toast.makeText(getApplicationContext(), "No make directory", Toast.LENGTH_LONG).show();
  }
}

I also added the following permission in the AndroidManifest.xml file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But it doesn't work. It just displays the toast message "No make directory".

Can anyone suggest where I am going wrong or propose an alternate method to implement the same?


回答1:


You can follow this link

Creating Folder in Internal memory

hopefully you are helpful from above link.

Best of luck!



来源:https://stackoverflow.com/questions/23774730/how-to-create-a-folder-in-the-phone-memory-not-sd-card-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!