ANDROID – Check Beacon Permission in Fragment

Home - ANDROID – Check Beacon Permission in Fragment

Ignatius Alex asked 5 months ago

Reason i used this code in fragment because MainActivity state onResume doesnt call when I move between fragment in MainActivity..
I want to check all requirement before begin scanning beacon (Cubeacon) in fragment, but i got error at “this” in if section. Error: checkAllRequirementUsingDefaultDialog (android.app.activity) in SystemRequirementManager cannot be applied to (com.eyro.mesosfer.pin.PetaFragment). How about the second this on cubeacon.connect(this).. What this sholud be replace with?
My code:

if (SystemRequirementManager.checkAllRequirementUsingDefaultDialog(this) {
// connecting to Cubeacon service when all requirements completed
cubeacon.connect(this);
// disable background mode, because we're going to use full
// scanning resource in foreground mode
cubeacon.setBackgroundMode(false);
}
1 Answers
Alann Maulana Staff answered 5 months ago

Hi Ignatius,
FYI, this in SystemRequirementManager.checkAllRequirementUsingDefaultDialog(this) is refers to activity instance. So if you want to access it within fragment, you can call getActivity() from within your fragment class.
Your final code will be :

if (SystemRequirementManager.checkAllRequirementUsingDefaultDialog(getActivity()) {
// connecting to Cubeacon service when all requirements completed
cubeacon.connect(this);
// disable background mode, because we're going to use full
// scanning resource in foreground mode
cubeacon.setBackgroundMode(false);
}
Ignatius Alex replied 5 months ago

Thank you..
It turn out i miss ‘)’ after getActivity. That’s why the program return error.

Ignatius Alex replied 5 months ago

Thank you..
It turn out i miss ‘)’ after getActivity. That’s why the program return error.

Ignatius Alex replied 5 months ago

Thank you..
It turn out i miss ‘)’ after getActivity. That’s why the program return error.

Your Answer