tbruyelle / RxPermissions

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

API 26 runtime permission #268

Closed dasbiswajit closed 5 years ago

dasbiswajit commented 5 years ago

My app needs below permissions. Which has been incorporated in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.autofocus"/>

After upgrading to API 26

(targetSdkVersion 26)

some functionality is not working. As I need to incorporate runtime permission. I am using RxPermission . The problem is my most of the implementations placed on helper class(not inside main activity). when I am trying to use helper library getting error - .Can not resolve constructor I have tried with the following options too -

RxPermissions rxPermissions = new RxPermissions((FragmentActivity) mContext);

As RxPermission require Fragment as target.Can we ask user all the permission in the main activity? A sample code will help me. Project code for refarance

ewoks commented 5 years ago

As README.MD states, you should pass Activity Context if you request permission from Activity or Fragment Context if you request permission from the Fragment. "NOTE: new RxPermissions(this) the this parameter can be an Activity or a Fragment"

in screenshot of example via RxPermission constructor you are passing "this", which is instance of LocalAlbumImagePickerHelper and RxPermission constructors are not prepared for it.

Now solution: Luckily you are injecting Context (I hope and assume Activity context) via constructor of LocalAlbumImagePickerHelper and you store it in mContext field. Use that exact mContext and pass it to new instance of RxPermissions instead of "this". Compile error should be gone.

p.s. please read documentation before you post similar "issues". Probably this was more for Stackoverflow. Adding more tickets like this makes, life of maintainers more difficult and real project issues can be lost in a noise of non important tickets.

ewoks commented 5 years ago

@tbruyelle IMHO this can be closed

dasbiswajit commented 5 years ago

@ewoks. Thanks. I have solved it. Ofcourse don't want to make developer unmanageable. I am able to fix this calling Rxpermission from from main activity

dasbiswajit commented 5 years ago

Closing the request

ewoks commented 5 years ago

glad that it worked out