0

I created a Notification using Notification.FLAG_ONGOING_EVENT. Now I want to use it as on/off switch just like bluetooth or wifi in Status bar.

I want to use it as on off switch for my service. If I click it, it will start the service and if I click it again it will off the service. Just like the bluetooth /wifi or other things in status bar. As I can't put anything on Status bar I want to use the notification bar in that way. Is it possible?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Bee
  • 104
  • 1
  • 13
  • "want to use it as on/off switch", can you please explain what this means? – verybadalloc Jun 20 '13 at 12:07
  • I want to use it as on off switch for my service. If I click it it will start the service and if I click it again it will off the service. Just like the bluetooth /wifi or other things in status bar.As I cant put anything on Status bar I want to use the notification bar in that way.Is it possible? – Bee Jun 20 '13 at 12:12

1 Answers1

0

Use a Pending intent that will launch your activty and put extras to know if u have to switch on/off.

// notification is clicked
Intent intent = new Intent(this, Main.class);
intent.putExtra(Main.SWITCH_ON, true);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

Extras bundle on the oncreate method

Bundle extras = getIntent().getExtras();
        if(extras != null && extras.containsKey(SWITCH_ON) && extras.getBoolean(SWITCH_ON)) {
            launchMyMethod();
        }
marshallino16
  • 2,645
  • 15
  • 29
  • have you used toggle switches to on-of? Actually I want to use the notification itself as the switch. If clicked it will lunch a service. If again clicked it will stop the service. Is there is a way like it? – Bee Jun 21 '13 at 04:57