{"id":15632694,"url":"https://github.com/reyhankaplan/react-native-ringer-mode","last_synced_at":"2025-07-24T21:11:40.493Z","repository":{"id":46976185,"uuid":"148849079","full_name":"reyhankaplan/react-native-ringer-mode","owner":"reyhankaplan","description":"React Native Ringer Mode - Get and set ringer mode on Android devices.","archived":false,"fork":false,"pushed_at":"2024-03-24T22:09:03.000Z","size":424,"stargazers_count":18,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T06:44:57.585Z","etag":null,"topics":["android","react","react-native","ringer","ringer-mode","volume"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/react-native-ringer-mode","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reyhankaplan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-14T22:49:45.000Z","updated_at":"2023-07-29T18:08:33.000Z","dependencies_parsed_at":"2024-06-21T16:33:40.578Z","dependency_job_id":"9552938e-f29c-4a45-9a1e-830fb3be9b84","html_url":"https://github.com/reyhankaplan/react-native-ringer-mode","commit_stats":null,"previous_names":["ryhnnl/react-native-ringer-mode"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reyhankaplan%2Freact-native-ringer-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reyhankaplan%2Freact-native-ringer-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reyhankaplan%2Freact-native-ringer-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reyhankaplan%2Freact-native-ringer-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reyhankaplan","download_url":"https://codeload.github.com/reyhankaplan/react-native-ringer-mode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251658196,"owners_count":21622819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","react","react-native","ringer","ringer-mode","volume"],"created_at":"2024-10-03T10:44:59.827Z","updated_at":"2025-04-30T06:45:03.668Z","avatar_url":"https://github.com/reyhankaplan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `react-native-ringer-mode` [![npm](https://img.shields.io/npm/v/react-native-ringer-mode)](https://www.npmjs.com/package/react-native-ringer-mode)\n\nReact Native Ringer Mode - Get and set ringer mode on Android devices.\n\n\u003e ⚠️ This package only supports Android. All functions will return `undefined` on non-Android devices. See https://github.com/reyhankaplan/react-native-ringer-mode/issues/3.\n\n## Installation\n\n```sh\nnpm install react-native-ringer-mode\n```\n\n## Usage\n\n### How to get and set ringer mode with `useRingerMode` hook\n\n```js\nimport React from 'react';\n\nimport { View, Text, Button } from 'react-native';\nimport { useRingerMode, RINGER_MODE } from 'react-native-ringer-mode';\n\nconst modeText = {\n  [RINGER_MODE.silent]: 'Silent',\n  [RINGER_MODE.normal]: 'Normal',\n  [RINGER_MODE.vibrate]: 'Vibrate',\n};\n\nexport default function App() {\n  const { mode, error, setMode } = useRingerMode();\n\n  return (\n    \u003cView\u003e\n      \u003cText\u003eRinger Mode: {mode !== undefined ? modeText[mode] : null}\u003c/Text\u003e\n\n      \u003cView\u003e\n        \u003cButton title=\"Silent\" onPress={() =\u003e setMode(RINGER_MODE.silent)} /\u003e\n        \u003cButton title=\"Normal\" onPress={() =\u003e setMode(RINGER_MODE.normal)} /\u003e\n        \u003cButton title=\"Vibrate\" onPress={() =\u003e setMode(RINGER_MODE.vibrate)} /\u003e\n      \u003c/View\u003e\n\n      \u003cView\u003e\n        \u003cText\u003e{error?.message}\u003c/Text\u003e\n      \u003c/View\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n### How to get ringer mode with `getRingerMode`\n\n`getRingerMode` is an async function and resolves the current ringer mode of the device.\n(Resolves `undefined` on non-Android devices.)\n\n```js\nimport React, { useEffect, useState } from 'react';\n\nimport { View, Text } from 'react-native';\nimport {\n  RINGER_MODE,\n  getRingerMode,\n  RingerModeType,\n} from 'react-native-ringer-mode';\n\nconst modeText = {\n  [RINGER_MODE.silent]: 'Silent',\n  [RINGER_MODE.normal]: 'Normal',\n  [RINGER_MODE.vibrate]: 'Vibrate',\n};\n\nexport default function App() {\n  const [mode, setMode] = useState\u003cRingerModeType | undefined\u003e();\n\n  useEffect(() =\u003e {\n    (async () =\u003e {\n      try {\n        const currentMode = await getRingerMode();\n        setMode(currentMode);\n      } catch (error) {\n        console.error(error);\n      }\n    })();\n  }, []);\n\n  return (\n    \u003cView\u003e\n      \u003cText\u003eRinger Mode: {mode !== undefined ? modeText[mode] : null}\u003c/Text\u003e\n    \u003c/View\u003e\n  );\n}\n\n```\n\n### How to set ringer mode with `setRingerMode`\n\n`setRingerMode` is an async function that sets the given ringer mode to the device and resolves the mode if it is set.\n(Resolves `undefined` on non-Android devices.)\n\n```js\nimport React from 'react';\n\nimport { View, Button } from 'react-native';\nimport {\n  setRingerMode,\n  RINGER_MODE,\n  RingerModeType,\n} from 'react-native-ringer-mode';\n\nexport default function App() {\n  const setMode = (mode: RingerModeType) =\u003e {\n    try {\n      setRingerMode(mode);\n    } catch (error) {\n      console.error(error);\n    }\n  };\n  return (\n    \u003cView\u003e\n      \u003cButton title=\"Silent\" onPress={() =\u003e setMode(RINGER_MODE.silent)} /\u003e\n      \u003cButton title=\"Normal\" onPress={() =\u003e setMode(RINGER_MODE.normal)} /\u003e\n      \u003cButton title=\"Vibrate\" onPress={() =\u003e setMode(RINGER_MODE.vibrate)} /\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n### Not allowed to change Do Not Disturb state `checkDndAccess` \u0026 `requestDndAccess`\n\nFrom N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See [AudioManager#setRingerMode](https://developer.android.com/reference/android/media/AudioManager#setRingerMode(int)).\n\nIf you want to change the ringer mode **from Silent mode** or **to Silent mode**, you may run into the `Not allowed to change Do Not Disturb state` error. The example below checks the DND access and if user hasn't given the access opens the settings for it.\n\nFirst you need to add the line below to your `AndroidManifest.xml` to be able to see your app in the settings.\n\n```xml\n\u003cuses-permission android:name=\"android.permission.ACCESS_NOTIFICATION_POLICY\" /\u003e\n```\n\nAnd you can check and request permission before setting the ringer mode. Example code below:\n\n```js\nimport React from 'react';\nimport { View, Button } from 'react-native';\n\nimport {\n  useRingerMode,\n  RINGER_MODE,\n  checkDndAccess,\n  requestDndAccess,\n  RingerModeType,\n} from 'react-native-ringer-mode';\n\nexport default function App() {\n  const { mode, setMode } = useRingerMode();\n\n  const changeMode = async (newMode: RingerModeType) =\u003e {\n    // From N onward, ringer mode adjustments that would toggle Do Not Disturb\n    // are not allowed unless the app has been granted Do Not Disturb Access.\n    // @see https://developer.android.com/reference/android/media/AudioManager#setRingerMode(int)\n    if (newMode === RINGER_MODE.silent || mode === RINGER_MODE.silent) {\n      const hasDndAccess = await checkDndAccess();\n      if (hasDndAccess === false) {\n        // This function opens the DND settings.\n        // You can ask user to give the permission with a modal before calling this function.\n        requestDndAccess();\n        return;\n      }\n    }\n\n    setMode(newMode);\n  };\n\n  return (\n    \u003cView\u003e\n      \u003cButton title=\"Silent\" onPress={() =\u003e changeMode(RINGER_MODE.silent)} /\u003e\n      \u003cButton title=\"Normal\" onPress={() =\u003e changeMode(RINGER_MODE.normal)} /\u003e\n      \u003cButton title=\"Vibrate\" onPress={() =\u003e changeMode(RINGER_MODE.vibrate)} /\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freyhankaplan%2Freact-native-ringer-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freyhankaplan%2Freact-native-ringer-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freyhankaplan%2Freact-native-ringer-mode/lists"}