Giving permission to another application to access my package

1

I have an application that has a certain audio file, which is in /data/data/meu_pacote/audio_anexo/audio.mp3 , so that's fine, the problem is that the MediaPlayer class of Android can not execute the file, and when I put the same file on the memory card, it runs smoothly .

I believe that since the /data/data/meu_pacote folder only belongs to my application, MediaPlayer can not access content that is inside it.

What is the solution?

Note: I already searched for Context.MODE_WORLD_READABLE .

Below is the code for creating the audio file, which I am using. Is there any parameter I need to pass?

File diraudio = new File("/data/data/br.meupacote.meuapp/audio_anexo/");
//Verifica se o diretorio nao existe e cria ele;
if(!diraudio.exists())
{
    Log.i("XDEBUG","Pasta para áudio foi criada!");
    diraudio.mkdir();
}

String caminho = dir + audiofile.getName();

InputStream in = new FileInputStream(audiofile);
byte[] b = IOUtils.toBytes(in);

File file = new File(caminho);  

@SuppressWarnings("resource")
FileOutputStream fos = new FileOutputStream(file);
fos.write(b);
    
asked by anonymous 28.05.2014 / 14:24

1 answer

1

I believe the biggest problem is that it is impossible to read the file and its location. The solution I found when I needed to read a file saved with my project was to put the file in the folder: MyProject-> assets.

In order to read the file open the "mp3" file using MediaPlayer the following is an example of a method I created:

 public void tocaMusica(String nomeFicheiro) throws IllegalArgumentException, IllegalStateException, IOException 
 {
     AssetFileDescriptor descriptor = null;
     try 
     {
        descriptor = getActivity().getAssets().openFd(nomeFicheiro);
     } 
     catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

     player = new MediaPlayer();

     //Definimos duas variaveis com o inicio e o fim da reproducao do ficheiro que obetmos dos metodos getStartOffset e getLength
     long start = descriptor.getStartOffset();
     long end = descriptor.getLength();

     //Definimos o DataSource do player com o ficheiro que pegamos usando o AssetFileDescriptor e o inicio e o fim do ficheiro.
     player.setDataSource(descriptor.getFileDescriptor(), start, end);
     player.prepare();

     player.setVolume(1.0f, 1.0f);
     player.start();

    }

In order to play the music, simply invoke the method called Music with the name of the file inside the assets folder as follows:

tocaMusica("teste.mp3");
    
13.06.2014 / 12:34