c19354837 / react-native-system-setting Goto Github PK
View Code? Open in Web Editor NEWA library to access system setting, and change it easily. eg: volume, brightness, wifi
License: MIT License
A library to access system setting, and change it easily. eg: volume, brightness, wifi
License: MIT License
Android has four different volumes (Media, Sound, Notifications, System). It seems like I get always the "active" volume, but this switches quite often. How to get/set a specific volume?
android的registerReceiver(volumeBR, filter)后是不是要注销
Hi,
Is there any way to enable the disable the the airplane mode
from react-native code, i.e without opening the settings and do on/off flight mode. is there any possibility to automatically on/off of flight mode.
setBrightness have the same second param showUI:true like setVolume ?
I want to catch the volume change button has been pressed but I don't want it to change the volume. Currently, I am catching the event with this library but I don't see how to stop its propagation.
Hello,
Is anyone using this to bring the user to the wifi selection page on iOS? It works on android but on iOS it only goes to the general settings page.
When I set the volume to 0 the system vibrates but makes no sound. However when I set the volume back to the initial setting, it plays a sound. Am I interpreting the playSound
configuration correctly? It shouldn't be playing a sound when I set the volume back up right?
Here's how I am calling the methods:
setVolume = (value) => {
SystemSetting.setVolume(value, {
type: 'ring',
playSound: false,
});
}
initializeVolume = () => {
SystemSetting.getVolume('ring').then((volume)=>{
this.setVolume(0);
this.initialVolume = volume;
});
}
componentWillUnmount() {
this.setVolume(this.initialVolume);
}
React version: "16.3.0-alpha.1"
React-Native version: "0.54.0"
React-Native-System-Setting: "^1.4.1"
OS: Android 5.1.1
On RN 0.56.0, when trying to build Android app using react-native-system-setting
, I see the following error output:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
> A problem occurred configuring project ':react-native-system-setting'.
> The SDK Build Tools revision (23.0.1) is too low for project ':react-native-system-setting'. Minimum required is 25.0.0
As of RN 0.56.0, the Android SDK versions used have been changed to the following:
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
It seems like react-native-system-setting
needs to be updated.
Hi, thanks for this great module first of all. I'm trying to use FusedLocation to get & follow the device location upon having the location setting switched on and getting the necessary permisson from the user (on Android). All is working ok except when the user selects a different mode than high accuracy. Is it possible if isLocationEnabled callback would provide the selected mode so that the we can redirect the user to right setting?
Hello,
On iOS only , isAirplaneEnabled()
always return true.
It works perfectly on Android. Maybe a config issue ?
Thanks 😄
Hi, I was trying to set the brightness to 1 when the component is mounted, and restore back to originalBrightness
when the component is unmounted. It works fine on Android 6.0, but it is way darker when the brightness is restored on Android 8.0. I found that I have to set > 1 (example 1.1) to restore to original brightness.
It is the same if I use saveBrightness
and restoreBrightness
combo.
class Screen extends React.Component {
async componentDidMount() {
const originalScreenBrightness = await SystemSetting.getAppBrightness();
this.setState({ originalScreenBrightness });
SystemSetting.setAppBrightness(1);
}
componentWillUnmount() {
const { originalScreenBrightness } = this.state;
// I have to set `1.1` to restore to the original screen brightness on Android 8.0
SystemSetting.setAppBrightness(1.1);
}
}
Versions:
react-native
: 0.51.0react-native-system-setting
: 1.2.5how can config vibrate in system setting of devices ?
I attempted to submit an app to the iOS App Store using react-native-system-setting
and received this scary rejection:
Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.
Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store.
Next Steps
To resolve this issue, please revise your app to provide the associated functionality using public APIs or remove the functionality using the "prefs:root" or "App-Prefs:root" URL scheme.
If there are no alternatives for providing the functionality your app requires, you can file an enhancement request.
The only place in my app that uses the "prefs:root=" non-public URL scheme is in react-native-system-setting
, specifically in react-native-system-setting/ios/RTCSystemSetting.m
starting at line 55:
-(void)initSetting{
BOOL newSys = [UIDevice currentDevice].systemVersion.doubleValue >= 10.0;
setting = @{@"wifi": (newSys?@"App-Prefs:root=WIFI" : @"prefs:root=WIFI"),
@"location": (newSys?@"App-Prefs:root=Privacy&path=LOCATION" : @"prefs:root=Privacy&path=LOCATION"),
@"bluetooth": (newSys?@"App-Prefs:root=Bluetooth" : @"prefs:root=Bluetooth"),
@"airplane": (newSys?@"App-Prefs:root=AIRPLANE_MODE" : @"prefs:root=AIRPLANE_MODE")
};
}
This package is fantastic, but this problem must be addressed, or users of this package simply can't submit to the iOS App Store.
Would be handy to define if the volume ui feedback is shown by default, now if you just want to track volume and nothing else, the volume feedback is suppressed.
It would be nice to be able to set if the ui is shown initially, since it is always turned off once you load react-native-system-setting.
| android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:639)
| com.ninty.system.setting.SystemSetting.setVolume (SystemSetting.java:274)
| java.lang.reflect.Method.invoke (Method.java)
| com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
| com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:160)
| com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
| android.os.Handler.handleCallback (Handler.java:808)
| android.os.Handler.dispatchMessage (Handler.java:101)
| com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:29)
| android.os.Looper.loop (Looper.java:166)
| com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run (MessageQueueThreadImpl.java:192)
| java.lang.Thread.run (Thread.java:784)
as title,
the code works on Android, but not affecting iOS,
any idea? thanks in advance.
Hi,
We're using CocoaPods to install some of the dependencies in our app, along with some libraries that are manually linked. The reason is that some libraries have issues when linked via CocoaPods and in those cases, I fall back to manual installation. It fails for this library too, but I'm unable to find any manual installation steps. Is manual installation not supported at all?
EDIT:
I was able to get a successful build by adding node-modules/react-native-system-setting/ios/RCTSystemSetting.xcodeproj
to Libraries. But now I'm getting an error Native module cannot be null
when running the app, coming from SystemSettting.js:11:21
. Is this because of an issue with linking the library?
After submitting my app with react-native-system-setting 1.5.3
to the iOS App Store I received the following mail:
Dear Developer,
We identified one or more issues with a recent delivery for your app. Please correct the following issues, then upload again.
Missing Purpose String in Info.plist File - Your app's code references one or more APIs that access sensitive user data. The app's Info.plist file should contain a NSBluetoothPeripheralUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data will be required to include a purpose string.If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn't contain the APIs. Learn more (https://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy).
Best regards,
The App Store Team
Since I don't use Bluetooth anywhere in the app, I guess it's because this package can manage bluetooth as well.
Does anyone else have a similar problem?
PS: I used setAppStore(true)
.
Is it possible to get support for airplane mode?
With the latest release the MPVolumeView UI is visible in the upper left corner. I can see the Airplay Button which is a little annoying. Should be fixable by adjusting the GCRect coordinates.
Great feature anyways!
Hey,
I have an issue using listeners for bluetooth and wifi states. I'm listening to EventWifiChange
and EventBluetoothChange
, but I noticed that the listeners are not active until I use the API's SwitchWifiSilence()
or the equivalent for bluetooth.
On the other side, it works immediately with addVolumeListener()
.
(I took the code from your example, and my implementation of listening to wifi and bluetooth states are directly inspired from your example).
After looking into the native code in SystemSetting.java
I think that I understood the reason for this:
listenVolume(reactContext)
is called directly in the SystemSetting()
constructor, but for wifi (resp. bluetooth), listenWifiState()
is only called in ReactMethod switchWifiSilence()
.
Is there a way to fix that ? Maybe by adding React Methods listenWifiState()
and listenBluetoothState()
or something like this ?
I hope what I say makes sense haha, I'm a total novice with react native and android development. Thanks for your attention.
Unexpected token (53:15)
51 | };
52 |
53 | SystemSetting.isLocationEnabled().then((enable)=>{
| ^
54 | const state = enable ? 'On' : 'Off';
55 | console.log('Current location is ' + state);
56 | })
what is the fix for that ?
Hi Ninty,
Thanks for creating this library!
A bug report (and a potential fix):
RNSS will cause crashes on Android devices if the volume is changed during app startup.
Caused by java.lang.RuntimeException
Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
The issue happens because users are able to interact with volumes before react is fully set up. That would cause a runtime exception.
I've created a PR with an empty try-catch to address this issue.
Regards,
Samuel
Hey first of all, thank you for this useful package !
I noticed that there was a way to switch Wifi silently (ie without opening the Android System Setting Page) with the method switchWifiSilence(complete).
I would love to have the same method for Bluetooth and Airplane Mode, is there any way to do this ?
SystemSetting.isLocationEnabled().then((enable)=>{
console.log(enable);
})
Enabling is always false even when my location is turned on. Others functions works fine for me.
i have just detached an expo project to be able to set the global volume ( i have never done it before), react-native link seems to work ok but when i try to use the setVolume method i get this error, am i doing something wrong? (I have also tried to link the library manually with no luck)
import SystemSetting from 'react-native-system-setting';
export default class DispositivoGenerico extends React.Component{
MudaVolume(InputValue){
var oldMax = 255;
var oldMin = 0;
var newMax = 100;
var newMin = 0;
var oldRange = oldMax - oldMin
var newRange = newMax - newMin
var newValue = ((InputValue - oldMin) * newRange / oldRange) + newMin;
SystemSetting.setVolume(newValue);
this.props.OnValueChangeSlider(InputValue);
}
This package is probably not intended to be used with tabs but I get the following error:
"Cannot read property 'setScreenMode' of undefined" coming from line 41 of SystemSetting.js
Attempting to setVolume
either to 0 or from 0 throws the following error:
Not allowed to change Do Not Disturb state`
Remote stack trace:
at
com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1905)
at
com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1847)
at
android.media.IAudioService$Stub.onTransaction(IAudioService.java:139)
at android.os.Binder.execTransact(Binder.java:731)
I have added this use-permission to my AndroidManifest as well as the library's to no avail:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
Environment:
OS: macOS Sierra 10.12.6
Node: 6.11.0
Yarn: 1.7.0
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: ~0.55.2 => 0.55.4
getting this warning when i run the app on my device.
Module RCTSystemSetting requires main queue setup since it overrides init
but doesn't implement requiresMainQueueSetup
. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
Hi and thank you for this great library.
On Android, could you please make AudioManager.FLAG_PLAY_SOUND as a parameter in your setVolume method in the SystemSetting.java ?
My point is that I don't want to have the device sound when changing the volume.
Thanks!
crash when call SystemSetting.setBrightnessForce(0.1);
exception:
com.xxx was not granted this permission: android.permission.WRITE_SETTINGS
RN: 0.48.4
ANDROID: 7.0
AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.READ_LOGS" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.SET_DEBUG_APP" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_PROFILE"/> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.webkit.permission.PLUGIN" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.CALL_PHONE" />
thanks a lot.
When i check ios location permiision i get location of my phone , but for my app it can be disabled, how i can check this case?
It works well on the iOS devices I've tested with, on the Android emulators, and on LineageOS 14.x Android phone.
On the Samsung Galaxy S8 (SM-G950U1) running Android 8.0.0 with Android security patch level from September 1, 2018, isLocationEnabled() resolves with 'enabled' when in fact the phone's Location settings are disabled.
This is for version 1.6.0
You should not base64 / obfuscate a private library call:
https://github.com/c19354837/react-native-system-setting/blob/master/ios/RTCSystemSetting.m#L70-L73
Originally filed and "fixed" here: #28
If it's not caught now it will be caught soon. Calling a private library is one thing, but getting a notice about it and then obfuscating the call and trying again is a sure fire way to get permanently rejected.
I do not advise anyone include this library or risk getting your app banned. The warning from apple mentioned doing exactly what you decided as safe, saying it in fact is not safe:
Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store.
Hello,
I'm trying to get the location permission status. I did try isLocationEnabled and getLocationMode on iOS:
Is there away to tell if the user enabled the 'Always' vs 'While using the app' option ? right now all I'm getting is 1 or 0
accessing isLocationEnabled or getLocationMode always returns 1 regardless of my app settings selection
I'm using
Hello,$for information, during the install
{
"react-native-system-setting": "1.4.2",
"react-native": "0.55.2",
"react": "16.3.1",
},
the link didn't work properly,
android/app/build.gradle
...
compile project(':react-native-system-setting')
}
didn't apply
result in a builing failure but log error is quiet clear
every thing else is fine
Hello!
I get an error when trying to set the system volume.
import SystemSetting from 'react-native-system-setting'
SystemSetting.setVolume(1, {
playSound: false,
})
This throws the following error:
Couldn't find key playSound in dynamic object
getBoolean
ReadableNativeMap.java
setVolume
SystemSetting.java:198
This also happens if I leave out the options object altogether.
react-native-system-setting 1.2.4
React Native 0.52.3
Android 5.1.1
SDK version in node_modules/react-native-system-setting/android/build.gradle
has been overwritten to be:
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 22
targetSdkVersion 26
}
}
I want when call function switchLocation Location auto change and don't move to screen setting of Android.
Who can help me?
Is it necessary to compile this for targets 10.3 and higher? I'm using over 25 libs and this is the only lib that requires me to update my target devices. Already having people complaining about not being to update to the latest version as they're not on OS 10.3 or higher.
Hi,
this is a good library but I noticed that when calling openWriteSetting() then the user is directed to the apps list. And when pressing back button, then the right app permissions page is displayed.
I did some digging in the source and seems that in SystemSetting.java:179 switchSetting(SysSettings.WRITESETTINGS) is called, which seems to be the cause of the redirection to the apps list.
@ReactMethod
public void openWriteSetting() {
Intent intent = new Intent(SysSettings.WRITESETTINGS.action, Uri.parse("package:" + mContext.getPackageName()));
mContext.getCurrentActivity().startActivityForResult(intent, SysSettings.WRITESETTINGS.requestCode);
switchSetting(SysSettings.WRITESETTINGS); // is this line necessary?
}
Hi,
I would like to be able to use the library on iOS using Cocoapods instead of react-native link
.
The only requirement needed is adding a podspec file.
Due to a breaking change in RN we must remove a method (or remove override on it). Change commit is at facebook/react-native@ce6fb33
react v16.3.1
react-native v0.55.4
react-native-system-setting v1.4.1
I readed API docs, but It hasn't method to listening when location change.
So, have other way to know when location change?
Thank you.
SystemSetting.addVolumeListener((data) => {
alert (data);
});
added inside render function. Am I missing anything. please help on how to add this listener.
Device: Nexus 69
OS: Android 8.0.0
package.json
:
{
"dependencies": {
"react-native": "^0.51.0",
"react-native-system-setting": "^1.5.0",
}
}
No matter what the device's brightness is set to, when I open my app, getAppBrightness
and getBrightness
always resolve to the same number. This isn't the intended behavior is it? Any idea what I can do to fix it?
For me location listener is working fine in android device but not able to get this working in ios device.
Hi,
I'm testing this library on a simulator. I do have a device but due to some strange bug with XCode, I'm unable to test it on the device.
On the simulator, when I Increase/Decrease the volume (Cmd + (Up/Down)), I can see the ios volume changing. Also, when I play something in my app, the playback volume changes as well. However, no volume change events are getting dispatched. I tried the example app and it's the same there as well. I moved the slider and it doesn't affect the volume shown by the OS. If I change the volume using the shortcut, the slider isn't getting updated either.
The same code works perfectly on Android and also the getVolume function is working on both Android and iOS. It's just the listener that has an issue on iOS.
Steps to reproduce the issue
Error log
Receiver not registered: com.ninty.system.setting.SystemSetting
setVolume -> SystemSetting.java
More error log
java.lang.IllegalArgumentException: Receiver not registered: com.ninty.system.setting.SystemSetting$1@4247e2a0
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:748)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1647)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:489)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:489)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.ninty.system.setting.SystemSetting.setVolume(SystemSetting.java:274)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:808)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:103)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at android.os.Looper.loop(Looper.java:193)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
08-03 09:30:52.258 8730 8783 E AndroidRuntime: at java.lang.Thread.run(Thread.java:848)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.