0

I've created an app which shows a notification if the budget is below 20%. Now I want that user can handle the notification (enable-disable) via Settings Preference. If the user disables the notification, he will not receive the notification. Here is my code for Settings preference:

<SwitchPreferenceCompat
    android:defaultValue="true"
    android:key="notify"
    android:title="Notification"
    android:summary ="Click to turn on or off"
/>

<SwitchPreferenceCompat
    android:defaultValue="true"
    android:key="key_vibrate"
    android:dependency="notify"
    android:summary="Vibrate on new notification"
    android:title="Vibrate" />

SsssZ
  • 21
  • 7
  • So what is the problem you are facing? Can you please post your code where you are showing notification? – Mayur Gajra Apr 11 '19 at 06:21
  • I'm not getting any error. By default when balance is less than 20%, notification is pop up. But I want that If user change disable the notification in an apps settings. No notification will be display. – SsssZ Apr 11 '19 at 06:24
  • Ohk then please post your code for showing notification and something related to it as well. – Mayur Gajra Apr 11 '19 at 06:31

1 Answers1

0

That you need manage manually For example when you change value of preference(SwitchPreferenceCompat) you should have receive call back in your class where you have implemented OnSharedPreferenceChangeListener listener

And in your Receiver class which is responsible for showing notification to user you need to check value of your preference. If it is true then show notification to user else dont show it

Thats it....

Also have look here