54852

SCREEN_BRIGHTNESS_MODE does not work with permission

Question:

In my app I want to change the SCREEN_BRIGHTNESS_MODE (and set another value). I added the permission in the AndroidManifest.xml (double checked with other parameters in the file). The value of the mode should be changed, when a button was pressed.

@Override public void onClick(View v) { if(on) { ContentResolver cResolver = getContentResolver(); Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, 50); } }

And the AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/> <activity android:name=".FullscreenActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@style/FullscreenTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

The Android device is a Logic Instrument Fieldbook F1 Android-Version 5.0.1

When I try to execute this command I got the following Exception:

08-31 15:29:28.471 16613-16613/com.matodayu.oxo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.matodayu.oxo, PID: 16613 java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS at android.os.Parcel.readException(Parcel.java:1540) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142) at android.content.ContentProviderProxy.call(ContentProviderNative.java:643) at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1094) at android.provider.Settings$System.putStringForUser(Settings.java:1371) at android.provider.Settings$System.putIntForUser(Settings.java:1476) at android.provider.Settings$System.putInt(Settings.java:1470) at com.matodayu.oxo.FullscreenActivity$4$1.run(FullscreenActivity.java:184) at android.app.Activity.runOnUiThread(Activity.java:5285) at com.matodayu.oxo.FullscreenActivity$4.onClick(FullscreenActivity.java:179) at android.view.View.performClick(View.java:4809) at android.view.View$PerformClick.run(View.java:20123) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5534) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)

Can anyone help me?

Answer1:

Where did you defined your permissions? Inside the manifest or application tag?

I made a Test-Project and it works. It just failed when i added the permission inside the wrong position - e.g. the application tag.

Recommend

  • What causes java.net.MalformedURLException: no protocol: when trying to deploy .ear in weblogic?
  • SQL Deleting/Replacing a part of a string
  • Passing string variable with spaces
  • JSON response and calling next() in Express
  • How to initialize std stack with std vector?
  • Realtime sound synthesizer from a varying input in Python
  • IISExpress application pool recycle
  • DateTime c# parsing
  • Connection refused on Docker tutorial get started part 4
  • How can I create a Spotlight-like search bar in an iPhone app?
  • Makefile Argument string comparision
  • Extracting Information from websites
  • Failed resolution of: Landroid/support/v7/widget/ListViewCompat;
  • C# Emgu : Use of DISOpticalFlow
  • How to call an action method using OGNL
  • Manifest marge error after migrating to androidX
  • Jaccard Similarity of an RDD with the help of Spark and Scala without Cartesian?
  • How to pass a parameter to an included page with JSF 1.2
  • Get All IP and Mac Address in lan
  • Share Application Through Facebook, Twitter, Email, and Messaging Only
  • Java Arithmetic division
  • How to send the client id and secret id of OAuth2 using Angular 2?
  • React Native - FlatList with dynamic height children
  • Getting specific color for specific value using JSON data
  • E: Malformed entry 1 in list file /etc/apt/sources.list.d/sbt.list (Suite)
  • Get the UTM tags with Facebook Marketing API
  • Network communication options in Java (Client/Server)
  • mssql script data insert or update
  • Check 'Manager can update membership list' in AD
  • Test for NULLs in multiple columns in MySQL
  • Signed Java web start application with Glassfish 4.1 and Java7
  • how to specify different css for ie
  • Rotating Towards Path in OpenGL
  • Problems to understand DXGI DirectX 11 Desktop Duplication to get a Buffer or Array
  • ssh remote server login script
  • convert json to excel in java