How To Set Custom Alarm Tone In Android
I need to set custom alarm tone in my App. Could anyone please just tell me how to set custom ringtone or Mp3 as an alarm ? Any kind of help will be appreciated.
Solution 1:
Solution 2:
You can use audio player to play your mp3.But here is a better alarm app which fulfills your requirements.
Solution 3:
in the Android docs look at the Status Bar Notifications page. In particular see the Adding a Sound section.
Solution 4:
Try this
add any .mp3 file in raw folder place name of that file
publicvoidsetAlarm() {
Filefile=newFile(Environment.getExternalStorageDirectory(),
"/Your Directory Name");
if (!file.exists()) {
file.mkdirs();
}
Stringpath= Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/Your Directory Name";
Filef=newFile(path + "/", filename + ".mp3");
UrimUri= Uri.parse("android.resource://" + getContext().getPackageName() + "/raw/" + filename);
ContentResolvermCr= getContext().getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile = mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile = null;
}
try {
byte[] readData = newbyte[1024];
FileInputStreamfis= soundFile.createInputStream();
FileOutputStreamfos=newFileOutputStream(f);
inti= fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
ContentValuesvalues=newContentValues();
values.put(MediaStore.MediaColumns.DATA, f.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, filename);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.MediaColumns.SIZE, f.length());
values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
Uriuri= MediaStore.Audio.Media.getContentUriForPath(f.getAbsolutePath());
getContext().getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + f.getAbsolutePath() + "\"", null);
UrinewUri= mCr.insert(uri, values);
try {
RingtoneManager.setActualDefaultRingtoneUri(getContext(),
RingtoneManager.TYPE_ALARM, newUri);
Settings.System.putString(mCr, Settings.System.ALARM_ALERT,
newUri.toString());
Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();
} catch (Throwable t) {
}
}
Post a Comment for "How To Set Custom Alarm Tone In Android"