Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needsUsageStatsPermission from sample appears to not be working as expected on 7.1 #6

Open
arenaq opened this issue May 24, 2017 · 5 comments

Comments

@arenaq
Copy link

arenaq commented May 24, 2017

I am using this snippet of yours inside of a service, but I always get null as a package name. Testing on Google Pixel, Android version 7.1

AppChecker appChecker = new AppChecker();
String packageName = appChecker.getForegroundApp(context);

My permissions look like this:

<uses-permission android:name="android.permission.GET_TASKS"/>
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions"/>
@ricvalerio
Copy link
Owner

ricvalerio commented May 24, 2017

Hi arenaq,

Are you requesting the Usage Stats permission to the user? Even though you have it set in the android manifest, unfortunately it still requires a manual acceptance from the user. In the sample code you may find code to call the relevant activity.

Here is what it looks like, taken from this file:

private void requestUsageStatsPermission() {
    if(!hasUsageStatsPermission(this)) {
        startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
    }
}

Cheers,
Ricardo

@arenaq
Copy link
Author

arenaq commented May 24, 2017

Yes, that was it. Thank you.

Only needsUsageStatsPermission does not work, because hasUsageStatsPermission returns always false, but I managed to get around this by calling requestUsageStatsPermission everytime.

Or do you have an idea how to fix needsUsageStatsPermission?

@ricvalerio
Copy link
Owner

That's odd. Let me take a look at it and I will come back to you. It might take a couple of days, sorry, a bit tight this week in time.

Cheers,
Ricardo

@ricvalerio ricvalerio changed the title Always null package name needsUsageStatsPermission from sample appears to not be working as expected on 7.1 May 25, 2017
@gdsomia
Copy link

gdsomia commented Jul 20, 2017

Have you fixed this? I would like to use this library.

@ricvalerio
Copy link
Owner

Hi,

Sorry for the delay. I tried to reproduce, but it is working correctly. In any case, I have released a new version, 1.1.0. This problem was not addressed but I recommend upgrading.

Will keep digging on this issue.

Cheers,
Ricardo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants