• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[Help Request] WRITE_SETTINGS-Permission

I am currently developing part of an application for a student-project. The section I have been assigned is supposed to change the screen brightness according to the value received from the brightness sensor. The code in itself is working perfectly fine, as long as the application has been given permission to alter system settings beforehand.
If started without permission the app will simply close on startup without requesting this permission at all. As far as I have been able to gather from e.g. stackoverflow, the permission needed is one of several `dangerous` permissions, that have their own quirks when it comes to requesting them at runtime.
Does anybody know of a way to accomplish this, or has encountered the same problem as me? If someone could tell me where to look, I would really be grateful.

PS: If needed I will of course provide the sourcecode. But so far this is cluttered enough as it stands.
 
the permission needed is one of several `dangerous` permissions, that have their own quirks when it comes to requesting them at runtime.

What are the specific permissions needed by the app to do this?
Did the app crash, or close unexpectedly. If so, can you post the stack trace from the Logcat?
 
Check this:
https://developer.android.com/reference/android/Manifest.permission.html#WRITE_SETTINGS

Now it depends by the Android version.
If API is <23 to have it in AndroidManifest.xml is enough.
For API >= 23, you have to request it at runtine (first time when the app starts after install).
How to do it: https://developer.android.com/training/permissions/requesting.html


You can have a look on my app https://play.google.com/store/apps/details?id=ro.notnull.IdenticalFilesFinder
If it is installed on Android v >=6.0 (API>=23) on the 1st run it will ask access to read/write files,photo,media ; because I want to read eventuallty to delete files from SD card.

In my code I have something like this:
Code:
MainActivity.java
...
// WANT_TO_WRITE_EXTERNAL_STORAGE was defined as
// private static final int WANT_TO_WRITE_EXTERNAL_STORAGE =1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, WANT_TO_WRITE_EXTERNAL_STORAGE);
    ...
    )


...

    @Override
    public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == WANT_TO_WRITE_EXTERNAL_STORAGE) {
            // check only the results
            for( int i=0; i< grantResults.length; i++) {
                if (grantResults[I] == PackageManager.PERMISSION_GRANTED) {
                    // access was granted ..
                    //
                }
            }
        }
    }
 
thank you for your help so far. currently digging through the development-websites and will give an update, when i´ve made any progress on the request at runtime.

PS: the only permission needed so far is the write_settings-permission, but i figure that as we start combining activities this will change
 
Back
Top Bottom