[Android] Add a Ringtone into the Android Emulator

Introduction:
Basically, there is no any ringtone in the Android emulator. You can add ringtone by the adb command. In the Android, you can place some many resources in the external storage that follows the default folder structure.

How to Add a Ringtone by myself?
The default folder structure is defined in the Android Developer: Saving files that should be shared. Here is the part of the article says the folder structure,

  • Music/ – Media scanner classifies all media found here as user music.
  • Podcasts/ – Media scanner classifies all media found here as a podcast.
  • Ringtones/ – Media scanner classifies all media found here as a ringtone.
  • Alarms/ – Media scanner classifies all media found here as an alarm sound.
  • Notifications/ – Media scanner classifies all media found here as a notification sound.
  • Pictures/ – All photos (excluding those taken with the camera).
  • Movies/ – All movies (excluding those taken with the camcorder).
  • Download/ – Miscellaneous downloads.

Here is the code shows the information about external storage directory,

        File externalStorageDirectory = Environment.getExternalStorageDirectory();
File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES);

By a Android application, we show the external storage directory and the public directory in the external storage.

So, we can create a folder named Ringtones in the /mnt/sdcard and add the audio files into the folder by the adb command. After re-mounting the SD card, we can observe the audio can be presents in the ringtone list.

Conclusion:
Follow the above steps, you can add your ringtone in the Android emulator.

發佈留言