privatevoidstartNotification(){Stringns=Context.NOTIFICATION_SERVICE;NotificationManagernotificationManager=(NotificationManager)getSystemService(ns);Notificationnotification=newNotification(R.drawable.ic_launcher,null,System.currentTimeMillis());RemoteViewsnotificationView=newRemoteViews(getPackageName(),R.layout.mynotification);//theintentthatisstartedwhenthenotificationisclicked(works)IntentnotificationIntent=newIntent(this,FlashLight.class);PendingIntentpendingNotificationIntent=PendingIntent.getActivity(this,0,notificationIntent,0);notification.contentView=notificationView;notification.contentIntent=pendingNotificationIntent;notification.flags|=Notification.FLAG_NO_CLEAR;//thisistheintentthatissupposedtobecalledwhenthe//buttonisclickedIntentswitchIntent=newIntent(this,switchButtonListener.class);PendingIntentpendingSwitchIntent=PendingIntent.getBroadcast(this,0,switchIntent,0);notificationView.setOnClickPendingIntent(R.id.closeOnFlash,pendingSwitchIntent);notificationManager.notify(1,notification);}publicstaticclassswitchButtonListenerextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,Intentintent){Log.d("Here","Iamhere");FlashOnOffflashLight;flashLight=newFlashOnOff();flashLight.flashLightOff();flashLight.releaseCamera();}}

and my xml:

<?xmlversion="1.0"encoding="UTF-8"?><LinearLayoutxmlns:android="android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"android:orientation="horizontal"android:weightSum="100"><ImageViewandroid:id="@+id/notifiation_p_w_picpath"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="30"android:contentDescription="@string/appImage"android:src="@drawable/ic_launcher"/><TextViewandroid:id="@+id/appName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="50"android:gravity="center"android:text="@string/flashLightOn"android:textAppearance="?android:attr/textAppearanceMedium"/><Buttonandroid:id="@+id/closeOnFlash"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="20"android:text="@string/close"/>

In manefest under Application tag:

<receiverandroid:name="FlashLight$switchButtonListener"/>