beworker / rx-android-permissions
posted
Category: RxJava
Minimum SDK Level: Jelly Bean (16 | 4.1.0 - 4.1.1)

Badge

View in Github Github project information
Starred: 104
Forks: 17
Watchers: 8
Open Issues: 1

Snapshot pictures

No snapshot for this library yet.

Description

Simple RxJava library for observing and requesting Android runtime permissions introduced in Android 6.0.

Observing permissions

Sometimes it makes sense to ask user for absolutely required permissions in a separate onboarding step. Simple code down below shows either main or onboarding fragment depending on permissions granted, without asking user for those permissions. This is pure observe case.

public class MainActivity extends AppCompatActivity {

    @Override public void onStart() {
        super.onStart();

        RxPermissions.get(this)
              .observe(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                       Manifest.permission.READ_EXTERNAL_STORAGE)
              .subscribe(granted -> {
                  if (granted) {
                      // you can pass to main fragment
                  } else {
                      // you can open onboarding fragment 
                  }
              });
    }
}
``