Move Raw file to SD card in Android

后端 未结 3 1931
醉酒成梦
醉酒成梦 2021-01-28 10:55

I have a method that will copy an Audio file from raw folder to SD card. It takes two inputs

  • ressound: .ogg Audio Raw file id.
  • fName: the fil
相关标签:
3条回答
  • 2021-01-28 11:10

    Use this for path:

    string baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    string path = baseDir + File.Separator + "music" + File.Separator + "yourpackagename" + filename;
    
    0 讨论(0)
  • 2021-01-28 11:14

    Please don't hardcode paths. Use Environment.getExternalStorageDirectory() to get the path of a large storage medium. Some phones mount sdcards in /mnt/sdcard or somewhere else, some just don't have one and rely on inbuilt flash.

    This might throw the error, but I don't think is the error in this case since you are probably testing with your phone/emulator, where this path applies.

    0 讨论(0)
  • 2021-01-28 11:27

    My problem has nothing to do with the code. It is a permission-related thing. I added the permission inside the application tag. It must be outside it. It must be in the root tag.

    Wired for me because it make sense to put it in the application tag not the Manifest tag !

    Thanks for your answers !

    0 讨论(0)
提交回复
热议问题