How to set Ringtone through nativescript?


It seems there is no plugin available for setting ringtone through nativescript, what are the other methods of doing this?

Ringtone Samsung

You can directly access the android native APIs to set your ringtone.

You need android.permission.WRITE_SETTINGS permission in your manifest for Android API Level < 23. For above ones you need to use the following,

if (android.provider.Settings.System.canWrite( {
  // write your code here
} else {
  const intent = new android.content.Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
  intent.setData("package:" +;

To set ringtone:

const file = new;

const values = new android.content.ContentValues();
values.put(android.provider.MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(android.provider.MediaStore.MediaColumns.TITLE, "Show me the meaning");
values.put(android.provider.MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(android.provider.MediaStore.Audio.AudioColumns.ARTIST, "None");
values.put(android.provider.MediaStore.MediaColumns.SIZE, new java.lang.Integer(file.length()));
values.put(android.provider.MediaStore.Audio.AudioColumns.IS_RINGTONE, new java.lang.Boolean(true));
values.put(android.provider.MediaStore.Audio.AudioColumns.IS_NOTIFICATION, new java.lang.Boolean(false));
values.put(android.provider.MediaStore.Audio.AudioColumns.IS_ALARM, new java.lang.Boolean(false));
values.put(android.provider.MediaStore.Audio.AudioColumns.IS_MUSIC, new java.lang.Boolean(false));

// Insert it into the database
const contentResolver =;
const uri = android.provider.MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
const newUri = contentResolver.insert(uri, values);
  .setActualDefaultRingtoneUri(,, newUri);

Note: Whenever you call contentResolver.insert, it will create a new entry. Make sure you delete unused / unwanted entries.


Hi Sir,
Me too have the same problem and have already tried with these codes. But it doen’t seem to work on javascript. Could you please tell what is the exact javascript code for setting ringtone in nativescript?
I have searched a lot for these, but could not find . I am a new bie to nativescript, so kindly help.


In general, even when you use TypeScript (with or without Angular or Vue frameworks) for development, end of the day it is transpiled to JavaScript. So it makes no difference, I had tested this code in Android 7.x and TNS 3.3.1 already.

If you are still facing issues, please post your error log.


Hi Sir,
Thanks ! It works :slight_smile: But my ringtone is being set to “None”, instead of the file I have choosen.
Previously this too didn’t happened, because of the wrong syntax of codes I have written.
Could you please tell why it is set to “None”?


It will be none only if the content uri is invalid / if it is not accessible. If you have your ringtone file in your app storage, try moving it to external storage.