Code Monkey home page Code Monkey logo

Comments (7)

samtstern avatar samtstern commented on August 18, 2024

@seang96 are you calling EasyPermissions.onRequestPermissionsResult in your Fragment?

from easypermissions.

samtstern avatar samtstern commented on August 18, 2024

Also make sure you always call super.onRequestPermissionsResult(requestCode, permissions, grantResults); whenever you Override it

from easypermissions.

seang96 avatar seang96 commented on August 18, 2024

Yeah, the method has both of those in there. I Implemented the class, I also tried @AfterPermissionGranted in the method that checks/requests/and handles what to do if the check succeeds, which only calls when I first check it.

    @AfterPermissionGranted(RC_FINE_LOCATION)
    public void locationPermissions() {
        String perm = Manifest.permission.ACCESS_FINE_LOCATION;
        if (EasyPermissions.hasPermissions(getContext(), perm)) {
            googleMap.getUiSettings().setMyLocationButtonEnabled(true);
            googleMap.setMyLocationEnabled(true);
        } else {
            EasyPermissions.requestPermissions(getContext(), "Would you like your location displayed with the bus route?", RC_FINE_LOCATION, perm);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        Log.i("mapFragment", "onPermissionsGranted:" + requestCode + ":" + perms.size());
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        Log.i("mapFragment", "onPermissionsDenied:" + requestCode + ":" + perms.size());
    }

from easypermissions.

samtstern avatar samtstern commented on August 18, 2024

Where you have requestPermissions(getContext(), ...) can you try replacing it with requestPermissions(this, ...) so that the object requesting the permissions is the Fragment?

from easypermissions.

seang96 avatar seang96 commented on August 18, 2024

Oh well, that worked. Was getContext() causing the method to be sent to the activity that the fragment is running in instead of the method inside of the fragment itself? Thanks for the fix.

from easypermissions.

samtstern avatar samtstern commented on August 18, 2024

Yeah returning results of permissions or startActivity calls to Fragments
relies on some interesting hacks that put the Fragment ID in the request
code. But if the calling context is not a Fragment the system doesn't know
to do that.

On Mon, May 23, 2016, 6:24 PM seang96 [email protected] wrote:

Oh well, that worked. Was getContext() causing the method to be sent to
the activity that the fragment is running in instead of the method inside
of the fragment itself? Thanks for the fix.


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#20 (comment)

from easypermissions.

nAkhmedov avatar nAkhmedov commented on August 18, 2024

I missed the last param so that i didn't receive @AfterPermissionGranted method calling.
Replace your code from
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults);
to
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);

from easypermissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.