Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR] Android: Unable to set system brightness #38

Open
pabichw opened this issue Nov 21, 2019 · 7 comments
Open

[ERROR] Android: Unable to set system brightness #38

pabichw opened this issue Nov 21, 2019 · 7 comments

Comments

@pabichw
Copy link

pabichw commented Nov 21, 2019

When trying to call:

ScreenBrightness.setBrightness(value) .then(() => {}, e => console.log('ERROR: ', e))
I receive this console log:

11-21 12:47:45.631 17605 17713 I ReactNativeJS: 'ERROR: ', { [Error: Unable to set system brightness]
11-21 12:47:45.631 17605 17713 I ReactNativeJS: framesToPop: 1,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: nativeStackAndroid:
11-21 12:47:45.631 17605 17713 I ReactNativeJS: [ { methodName: 'setSystemBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 192,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'setBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 271,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke', lineNumber: -2, file: 'Method.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 372,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaMethodWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 158,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaModuleWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'run',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: -2,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'NativeRunnable.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'handleCallback',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 794,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 99,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 29,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'MessageQueueThreadHandler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'loop', lineNumber: 176, file: 'Looper.java' } ],
11-21 12:47:45.631 17605 17713 I ReactNativeJS: userInfo: null

Happens on Android only. Works fine on iOS

@AboutReact
Copy link

Have you added the following permission?

<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />

You can visit Control Device Brightness from React Native App for a clear idea.

@HonzaJiran
Copy link

Adding permission is not enough, you have to ask user to enable this permission fe. using PermissionsAndroid.

@hakoniemi
Copy link

hakoniemi commented Feb 24, 2020

Adding permission is not enough, you have to ask user to enable this permission fe. using PermissionsAndroid.

I tested PermissionsAndroid on RN 0.61.2 and it doesn't offer access to WRITE_SETTINGS and it'll throw an error instead.

Of course it'd be great if some developer with skills would update the library to support Android X access to system level.

@kkkasio
Copy link

kkkasio commented Jul 29, 2020

Adicionar permissão não é suficiente, você deve pedir ao usuário para habilitar esta permissão fe. usando PermissionsAndroid.

Testei o PermissionsAndroid no RN 0.61.2 e ele não oferece acesso ao WRITE_SETTINGS e, em vez disso, gera um erro.

É claro que seria ótimo se algum desenvolvedor com habilidades atualizasse a biblioteca para oferecer suporte ao acesso do Android X ao nível do sistema.

Did you manage to solve this in some way for android ??

@tunm2020
Copy link

Have you added the following permission?

<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />

You can visit Control Device Brightness from React Native App for a clear idea.

version react-native: 0.59.10 not working with permission

@tunm2020
Copy link

When trying to call:

ScreenBrightness.setBrightness(value) .then(() => {}, e => console.log('ERROR: ', e))
I receive this console log:

11-21 12:47:45.631 17605 17713 I ReactNativeJS: 'ERROR: ', { [Error: Unable to set system brightness]
11-21 12:47:45.631 17605 17713 I ReactNativeJS: framesToPop: 1,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: nativeStackAndroid:
11-21 12:47:45.631 17605 17713 I ReactNativeJS: [ { methodName: 'setSystemBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 192,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'setBrightness',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 271,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'ScreenBrightnessModule.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke', lineNumber: -2, file: 'Method.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 372,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaMethodWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'invoke',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 158,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'JavaModuleWrapper.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'run',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: -2,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'NativeRunnable.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'handleCallback',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 794,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 99,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'Handler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'dispatchMessage',
11-21 12:47:45.631 17605 17713 I ReactNativeJS: lineNumber: 29,
11-21 12:47:45.631 17605 17713 I ReactNativeJS: file: 'MessageQueueThreadHandler.java' },
11-21 12:47:45.631 17605 17713 I ReactNativeJS: { methodName: 'loop', lineNumber: 176, file: 'Looper.java' } ],
11-21 12:47:45.631 17605 17713 I ReactNativeJS: userInfo: null

Happens on Android only. Works fine on iOS

Have you solved this problem yet and give me the solution..please!

@herbertvuijk
Copy link

herbertvuijk commented Aug 12, 2020

It's not working because you don't have the permission to change the setting. The ScreenBrightness module has functions exposed to React Native to ask for those permissions

Change your manifest to:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kiter" **xmlns:tools="http://schemas.android.com/tools"**>

And add:

<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions"/>

Next before using the setBrightness method in JS add this:
let hasPerm = await ScreenBrightness.hasPermission();

					if(!hasPerm){
						 ScreenBrightness.requestPermission();
						 return;
					}

I've updated the documentation as well, somebody should make my changes available soon I guess on the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@hakoniemi @herbertvuijk @HonzaJiran @pabichw @kkkasio @AboutReact @tunm2020 and others