Preference checkbox and BroadcastReceiver how to?

Put your problem here if it does not fit any of the other categories.

Preference checkbox and BroadcastReceiver how to?

Postby punticci » Fri Jul 05, 2013 9:52 am

my battery application has a settings menu in wich there are basically 3 checkbox. In the first (the main, until this is uncheked the others are not clickable) there is the option to activate the nofications in the navigation bar. In the others it's possible to choose what show in the notification. Now the xml of the preference.
Code: Select all
<PreferenceCategory
    android:summary="Settings"
    android:title="Settings" >

    <CheckBoxPreference
        android:defaultValue="true"
        android:key="first"
        android:summary="@string/summary_show"
        android:title="@string/Show_notifications" />

    <CheckBoxPreference
        android:defaultValue="false"
        android:dependency="first"
        android:key="second"
        android:summary="@string/summary_level"
        android:title="@string/title_battery_level" />

    <CheckBoxPreference
        android:defaultValue="false"
        android:dependency="first"
        android:key="third"
        android:summary="@string/summary_temp"
        android:title="@string/title_temperature" />
</PreferenceCategory>

Now, in my ActivityMain i have the code to show the informations about the battery through the BroadcastReceiver(i write only for the battery level because i think the other is the same):
Code: Select all
private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {

        @override
        public void onReceive(Context context, Intent intent) {         

            int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
                     . . .

            String[] statusbatt = {
                "Battery level: " +level+"%",
                . . .};
            ListView lvStatus = (ListView) findViewById(R.id.lv_status);
            lvStatus.setAdapter(new ArrayAdapter<String>(MainActivity.this, R.layout.list, statusbatt));
            info.getListViewSize(lvStatus);     
          }
};

And the last thing is the notification's code:
Code: Select all
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new               Notification.Builder(getApplicationContext())
.setContentTitle("Battery Informations")
.setContentText("Batteria al"+" "+level+"%")
.setSmallIcon(R.drawable.icon_small_not)
.setTicker(level+"%")
.build();

notification.flags = Notification.FLAG_ONGOING_EVENT;

Intent i = new Intent(context, MainActivity.class);

PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);

notifi.notify(215,notification);

Actually the notification start when launch the application and i can't turn it off and it's because i need to make the settings to check and choose if display it or not. What i want is that in a new activity, settings.java, when i press the first check box i can activate the notifications and then, by what you decide, the notifications appears. I mean, i check the first (the notifications are now avaible), i choose to display the battery level in the notification and the temperature so now they added in the notification. Hope you understand. thanks
punticci
Freshman
Freshman
 
Posts: 2
Joined: Fri Jul 05, 2013 9:49 am

Top

Re: Preference checkbox and BroadcastReceiver how to?

Postby punticci » Fri Jul 05, 2013 10:26 am

Please i need a help. I'm desperate
punticci
Freshman
Freshman
 
Posts: 2
Joined: Fri Jul 05, 2013 9:49 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests