I want to download a file and store it somewhere in my app, for example SharedPreferences
, then I want to play it when a remote push notification is sent.
Is it possible? If so, where is the best place to store this audio file?
I want to download a file and store it somewhere in my app, for example SharedPreferences
, then I want to play it when a remote push notification is sent.
Is it possible? If so, where is the best place to store this audio file?
use raw/ folder
Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.
And after Downloading use it like this
MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.soundclip);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.start();