refs:
https://github.com/tbruyelle/RxPermissions
https://www.jianshu.com/p/c3546e5cd2ff
https://www.jianshu.com/p/314e9e27592f
allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { implementation 'com.github.tbruyelle:rxpermissions:0.10.2' }
package com.example.testperms; import android.Manifest; import android.annotation.SuppressLint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.tbruyelle.rxpermissions2.RxPermissions; public class RxPermActivity extends AppCompatActivity { @SuppressLint("CheckResult") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rx_perm); final RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity or Fragment instance // Must be done during an initialization phase like onCreate rxPermissions .request(Manifest.permission.CAMERA, Manifest.permission.READ_PHONE_STATE) .subscribe(granted -> { if (granted) { // Always true pre-M // I can control the camera now } else { // Oups permission denied } }); } }