├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── reactlibrary │ └── androidsettings │ ├── RNANAndroidSettingsLibraryModule.java │ └── RNANAndroidSettingsLibraryPackage.java ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | 2 | # react-native-android-settings-library 3 | 4 | A react-native component to open Android settings 5 | 6 | ## Getting started 7 | 8 | `$ npm install react-native-android-settings-library --save` 9 | 10 | ### Mostly automatic installation 11 | 12 | `$ react-native link react-native-android-settings-library` 13 | 14 | ### Manual installation 15 | 16 | 17 | #### Android 18 | 19 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java` 20 | - Add `import com.reactlibrary.androidsettings.RNANAndroidSettingsLibraryPackage;` to the imports at the top of the file 21 | - Add `new RNANAndroidSettingsLibraryPackage()` to the list returned by the `getPackages()` method 22 | 2. Append the following lines to `android/settings.gradle`: 23 | ``` 24 | include ':react-native-android-settings-library' 25 | project(':react-native-android-settings-library').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-settings-library/android') 26 | ``` 27 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 28 | ``` 29 | compile project(':react-native-android-settings-library') 30 | ``` 31 | 32 | 33 | ## Usage 34 | Require the `react-native-android-settings-library` module. 35 | ```javascript 36 | import RNANAndroidSettingsLibrary from 'react-native-android-settings-library'; 37 | ``` 38 | 39 | Show system settings 40 | ```javascript 41 | RNANAndroidSettingsLibrary.main(); 42 | ``` 43 | 44 | Show certain settings 45 | ```javascript 46 | RNANAndroidSettingsLibrary.open('ACTION_WIFI_SETTINGS'); 47 | ``` 48 | 49 | Here are list of settings [android settings](https://developer.android.com/guide/components/intents-common.html#Settings) 50 | - ACTION_SETTINGS 51 | - ACTION_WIRELESS_SETTINGS 52 | - ACTION_AIRPLANE_MODE_SETTINGS 53 | - ACTION_WIFI_SETTINGS 54 | - ACTION_APN_SETTINGS 55 | - ACTION_BLUETOOTH_SETTINGS 56 | - ACTION_DATE_SETTINGS 57 | - ACTION_LOCALE_SETTINGS 58 | - ACTION_INPUT_METHOD_SETTINGS 59 | - ACTION_DISPLAY_SETTINGS 60 | - ACTION_SECURITY_SETTINGS 61 | - ACTION_LOCATION_SOURCE_SETTINGS 62 | - ACTION_INTERNAL_STORAGE_SETTINGS 63 | - ACTION_MEMORY_CARD_SETTINGS 64 | - ACTION_APPLICATION_DETAILS_SETTINGS 65 | 66 | 67 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | apply plugin: 'com.android.library' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "27.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 16 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | ndk { 14 | abiFilters "armeabi-v7a", "x86" 15 | } 16 | } 17 | lintOptions { 18 | warning 'InvalidPackage' 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation 'com.facebook.react:react-native:+' // From node_modules 24 | } -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactlibrary/androidsettings/RNANAndroidSettingsLibraryModule.java: -------------------------------------------------------------------------------- 1 | 2 | package com.reactlibrary.androidsettings; 3 | 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.provider.Settings; 7 | 8 | import com.facebook.react.bridge.ReactApplicationContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | import com.facebook.react.bridge.Callback; 12 | 13 | public class RNANAndroidSettingsLibraryModule extends ReactContextBaseJavaModule { 14 | 15 | private final ReactApplicationContext reactContext; 16 | 17 | public RNANAndroidSettingsLibraryModule(ReactApplicationContext reactContext) { 18 | super(reactContext); 19 | this.reactContext = reactContext; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "RNANAndroidSettingsLibrary"; 25 | } 26 | 27 | @ReactMethod 28 | public void open(String type_setting) { 29 | Intent intentCl = new Intent(); 30 | Uri uri = Uri.fromParts("package", reactContext.getPackageName(), null); 31 | 32 | switch (type_setting) { 33 | case "ACTION_SETTINGS": 34 | intentCl.setAction(Settings.ACTION_SETTINGS); 35 | break; 36 | case "ACTION_WIRELESS_SETTINGS": 37 | intentCl.setAction(Settings.ACTION_WIRELESS_SETTINGS); 38 | break; 39 | case "ACTION_AIRPLANE_MODE_SETTINGS": 40 | intentCl.setAction(Settings.ACTION_AIRPLANE_MODE_SETTINGS); 41 | break; 42 | case "ACTION_WIFI_SETTINGS": 43 | intentCl.setAction(Settings.ACTION_WIFI_SETTINGS); 44 | break; 45 | case "ACTION_APN_SETTINGS": 46 | intentCl.setAction(Settings.ACTION_APN_SETTINGS); 47 | break; 48 | case "ACTION_BLUETOOTH_SETTINGS": 49 | intentCl.setAction(Settings.ACTION_BLUETOOTH_SETTINGS); 50 | break; 51 | case "ACTION_DATE_SETTINGS": 52 | intentCl.setAction(Settings.ACTION_DATE_SETTINGS); 53 | break; 54 | case "ACTION_LOCALE_SETTINGS": 55 | intentCl.setAction(Settings.ACTION_LOCALE_SETTINGS); 56 | break; 57 | case "ACTION_INPUT_METHOD_SETTINGS": 58 | intentCl.setAction(Settings.ACTION_INPUT_METHOD_SETTINGS); 59 | break; 60 | case "ACTION_DISPLAY_SETTINGS": 61 | intentCl.setAction(Settings.ACTION_DISPLAY_SETTINGS); 62 | break; 63 | case "ACTION_SECURITY_SETTINGS": 64 | intentCl.setAction(Settings.ACTION_SECURITY_SETTINGS); 65 | break; 66 | case "ACTION_LOCATION_SOURCE_SETTINGS": 67 | intentCl.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 68 | break; 69 | case "ACTION_INTERNAL_STORAGE_SETTINGS": 70 | intentCl.setAction(Settings.ACTION_INTERNAL_STORAGE_SETTINGS); 71 | break; 72 | case "ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS": 73 | intentCl.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); 74 | intentCl.setData(uri); 75 | break; 76 | case "ACTION_MEMORY_CARD_SETTINGS": 77 | intentCl.setAction(Settings.ACTION_MEMORY_CARD_SETTINGS); 78 | break; 79 | case "ACTION_APPLICATION_DETAILS_SETTINGS": 80 | intentCl.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 81 | intentCl.setData(uri); 82 | break; 83 | default: 84 | intentCl.setAction(Settings.ACTION_SETTINGS); 85 | break; 86 | } 87 | 88 | 89 | intentCl.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 90 | reactContext.startActivity(intentCl); 91 | } 92 | 93 | @ReactMethod 94 | public void main() { 95 | open("main"); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactlibrary/androidsettings/RNANAndroidSettingsLibraryPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.reactlibrary.androidsettings; 3 | 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | public class RNANAndroidSettingsLibraryPackage implements ReactPackage { 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Arrays.asList(new RNANAndroidSettingsLibraryModule(reactContext)); 17 | } 18 | 19 | // Do not annotate the method with @Override 20 | // This will provide backward compatibility for apps using react-native version < 0.47 21 | // Breaking change in react-native version 0.47 : Android Remove unused createJSModules calls 22 | // Find more information here : https://github.com/facebook/react-native/releases/tag/v0.47.2 23 | // https://github.com/facebook/react-native/commit/ce6fb337a146e6f261f2afb564aa19363774a7a8 24 | public List> createJSModules() { 25 | return Collections.emptyList(); 26 | } 27 | 28 | @Override 29 | public List createViewManagers(ReactApplicationContext reactContext) { 30 | return Collections.emptyList(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | import { NativeModules } from 'react-native'; 3 | 4 | const { RNANAndroidSettingsLibrary } = NativeModules; 5 | 6 | export default RNANAndroidSettingsLibrary; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-settings-library", 3 | "version": "1.0.6", 4 | "description": "It allows to open android settings in React Native", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/Aleksandern/react-native-android-settings-library" 12 | }, 13 | "keywords": [ 14 | "react-native" 15 | ], 16 | "author": "Aleksandern", 17 | "license": "ISC" 18 | } 19 | --------------------------------------------------------------------------------