tbruyelle / RxPermissions

Android runtime permissions powered by RxJava2
Apache License 2.0
10.48k stars 1.31k forks source link

SDK 23 not work for WRITE_SETTINGS #51

Closed john990 closed 8 years ago

john990 commented 8 years ago
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (!Settings.System.canWrite(activity)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                intent.setData(Uri.parse("package:" + activity.getPackageName()));
                activity.startActivity(intent);
            }
        }

should like this...

tbruyelle commented 8 years ago

I didn't understand

tbruyelle commented 8 years ago

Close because no response

maxxx commented 7 years ago

Same issue for that permission (defined in manifest also). Let's try to re-open issue. my test code inside of onCreate in activity:

        new RxPermissions(this)
                .requestEach(Manifest.permission.CHANGE_NETWORK_STATE, Manifest.permission.WRITE_SETTINGS, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                .subscribe(permission -> {
                    if (permission.granted) {
                        // granted
                    } else {
                        Toast.makeText(this, "You must allow required permission " + permission.name, Toast.LENGTH_LONG).show();
                    }
                });

You will see not granted toast. tested on android emulators - api 23/24 and on asus zenfone max 3 api 24. Only location request dialog is visible to user.

aptly-io commented 6 years ago

I've the same issue on an LG5 (Android 7.0): WRITE_SETTINGS dialog never appears. It always ends up in the Permission denied (never asked again).

There are some SO entries on WRITE_SETTINGS with people having the same issue:

This is my minimalistic code (the manifest not listed):

build.gradle:

dependencies {
    // ... left out some defaults:
    compile 'io.reactivex.rxjava2:rxjava:2.1.7'
    compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
    compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'
}

MainActivity.java:

import android.Manifest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.jakewharton.rxbinding2.view.RxView;
import com.tbruyelle.rxpermissions2.RxPermissions;

public class MainActivity extends AppCompatActivity {

    private final static String TAG = "MAINAPP";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions.setLogging(true);

        setContentView(R.layout.activity_main);

        RxView.clicks(findViewById(R.id.button))
                .compose(rxPermissions.ensureEach(
                        Manifest.permission.CAMERA,
                        Manifest.permission.ACCESS_WIFI_STATE,
                        Manifest.permission.CHANGE_WIFI_STATE,
                        Manifest.permission.WRITE_SETTINGS))
                .subscribe(permission -> {
                    if (permission.granted) {
                        Log.d(TAG, "Permission granted for " + permission.name);
                    } else if (permission.shouldShowRequestPermissionRationale) {
                        Log.d(TAG, "Permission denied (can ask again) for " + permission.name);
                    } else {
                        Log.d(TAG, "Permission denied (never asked again) for " + permission.name);
                    }
                });
    }
}