ricvalerio / foregroundappchecker

Foreground application detection library for android.
Apache License 2.0
191 stars 50 forks source link

packageName returns null #12

Open dragneel30 opened 5 years ago

dragneel30 commented 5 years ago
AppChecker appChecker = new AppChecker();
        appChecker.whenAny(new AppChecker.Listener() {
                    @Override
                    public void onForeground(String packageName) {
                        Log.d("foreground: ", "" + packageName);
                    }
                }).timeout(1000)

packageName always give me null. Im calling the code inside a service,

TIA.

imspikey commented 5 years ago

Are you sure that Allow usage tracking is enabled? I had the same problem and after showing the permission and enabled it it worked fine

ricvalerio commented 5 years ago

@dragneel30,

Like @imspikey suggested, please confirm you added the right permissions, and also request them in runtime. Try to run the example and see if it works on the same device.

The reason why it returns null is because it's not capable of retrieving the packageName, and one of the reasons is permissions not having been granted.