How to check if Nearby Share is enabled on an Android device in Java

56 Views Asked by At

"I am developing an Android app in Java and I need to implement a feature where the app checks if the Nearby Share option on the user's device is turned on. When the user clicks a button, a toast message should appear indicating whether Nearby Share is enabled or not. How can I implement this functionality?"

I tried below code segment

private boolean isNearbyShareEnabled() {
    ContentResolver contentResolver = getContext().getContentResolver();
    int value = Settings.Secure.getInt(contentResolver, "nearby_sharing_state", -1);
    return value == 2;
}

Used this code segment inside my Adapter class

0

There are 0 best solutions below