1

I was trying to save an mp3 file into my application res/raw/ folder but i dont know actualy how to do this..

When button is clicked

OnClickListener button2 = new OnClickListener(){

    @Override
    public void onClick(View v) {

          Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("file/*");
            int YOUR_RESULT_CODE = 0;         
            intent.getData();
            startActivityForResult(intent, YOUR_RESULT_CODE);

    }

};

That was because i want to use a file explorer to select my .mp3 file type

Now how can i save the selected file to a specific folder (res/raw) into my application

    public File getTempFile(Context context, String url) {
   //should i add something here?
    File file1 = null;
    try {
        String FileName = Uri.parse(url).getLastPathSegment();
        file1 = File.createTempFile(FileName, null, context.getCacheDir());
    }
    catch (IOException e) {

    }
    return file1;

}

I would much appreciate if your examples contain code thanks in advance :)

noobProgrammer
  • 1,443
  • 4
  • 14
  • 33

2 Answers2

1

The .apk file is read only so the directory structure which are in that apk file follows the same, So no one can write this files or make changes on that at runtime,that's why You can't make a changes in /raw OR /assert folder at runtime.

Its apply on all the directories which are build in .apk files. As per docs.

You can't make change in raw folder once apk in build........

you have other option

  1. Internal storage (private are for you app)
  2. External Storage (like SD card)
  3. Database

You can find ur alternative answer here

Community
  • 1
  • 1
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
0

This tutorial gives useful description about how to save essential files of an application in the apk file.

Esmaeil MIRZAEE
  • 1,110
  • 11
  • 14