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

Java.lang error when trying to use nativescript-brightness #15

Closed
DeadEnglish opened this issue Mar 27, 2019 · 2 comments
Closed

Java.lang error when trying to use nativescript-brightness #15

DeadEnglish opened this issue Mar 27, 2019 · 2 comments
Labels
question Further information is requested

Comments

@DeadEnglish
Copy link

When using nativescript-brightness within my app. I am receiving the following java runtime error.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getOpPackageName()' on a null object reference
JS:     android.provider.Settings$System.canWrite(Settings.java:4203)

It seems like the app is requesting permissions but is unable to get them due to being above API Level 23 and needing the user to request them. After altering my app to request settings permissions, I am still getting the same error as above. I have added the code below from m yapp.component.ts and my main-activity.ts where I request settings permissions.

Which platform(s) does your issue occur on?

  • Android
  • API Level 26
  • emulator & device (HUAWEI MediaPad T3)

Please, provide the following version numbers that your issue occurs with:

  • CLI: 4.2.3
  • Cross-platform modules: 4.2.1
  • Runtime(s): 4.2.0
  • Plugin(s): (look for the version numbers in the package.json file of your
    project and paste your dependencies and devDependencies here)

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

Is there any code involved?

// app.component.ts
import { Brightness } from 'nativescript-brightness';

const screenBrightness = new Brightness();

screenBrightness.set({ intensity: 20 });
// main-activity.ts
/** Called when the activity is first created. */
public onCreate(savedInstanceState: android.os.Bundle): void {
	if (!this._callbacks) {
		setActivityCallbacks(this);
	}

	// Check whether has the write settings permission or not.
	let settingsCanWrite: boolean = android.provider.Settings.System.canWrite(this);

	if (!settingsCanWrite) {
		const intent = new android.content.Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
		// If do not have write settings permission then open the Can modify system settings panel.
		this.startActivity(intent);
	}
}
@elena-p
Copy link
Contributor

elena-p commented Apr 2, 2019

Hi @DeadEnglish,
Could you try the demo project to check whether the error appears? We have tested with API Level 26 and 28 and it works as expected. You are not required to request settings permissions as it is done internally by the plugin. What you need to do is add <uses-permission android:name="android.permission.WRITE_SETTINGS"/> in your AndroidManifest.xml

@elena-p elena-p added the question Further information is requested label Apr 2, 2019
@vakrilov vakrilov added this to Backlog in Plugins Team Apr 15, 2019
@elena-p
Copy link
Contributor

elena-p commented May 2, 2019

closing due to inactivity

@elena-p elena-p closed this as completed May 2, 2019
Plugins Team automation moved this from Backlog to Done May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Plugins Team
  
Done
Development

No branches or pull requests

2 participants