David_D
David_D

Reputation: 1402

Led notification preferences when battery is BATTERY_LOW?

How can i create a simple radio button preferences to choose which led color use in BATTERY_LOW condition?

Upvotes: 0

Views: 243

Answers (1)

LordMarty
LordMarty

Reputation: 1591

To change the led color: Check this link

For the BATTERY_LOW you will need a broadcastreceiver: Check this link

Ok.

First, create a file in the values folder. Call it something like "preference_res.xml". Then add the following:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string-array
    name="prefColor">
    <item>None</item>
    <item>Blue</item>
    <item>Green</item>
    <item>Yellow</item>
    <item>Other Color</item>
</string-array>
<string-array
    name="prefColorVal">
    <item>-1</item>
    <item>-2</item>
    <item>79</item>
    <item>24</item>
    <item>25</item>
    <item>27</item>
    <item>80</item>
</string-array>
 </resources>

(Be aware that the prefColorVal items should ref to the value you want the radio button to have. The values shown here are random.)

In your preference.xml, add something like this:

<ListPreference
    android:dialogTitle="Choose color"
    android:entries="@array/prefColor"
    android:entryValues="@array/prefColorVal"
    android:key="bat_below_15"
    android:negativeButtonText="Cancel"
    android:positiveButtonText="Save"
    android:summary="Choose color when below 15"
    android:title="Color when below 15" />

If you don't know how to get or use these values, here are some pointers, but you should google this stuff:

preferences = PreferenceManager.getDefaultSharedPreferences(ctx);

and use this to get the value:

  preferences.getString("bat_below_15", Blue));

Upvotes: 0

Related Questions