您好,登錄后才能下訂單哦!
private void startNotification(){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis()); RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.mynotification); //the intent that is started when the notification is clicked (works) Intent notificationIntent = new Intent(this, FlashLight.class); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentView = notificationView; notification.contentIntent = pendingNotificationIntent; notification.flags |= Notification.FLAG_NO_CLEAR; //this is the intent that is supposed to be called when the //button is clicked Intent switchIntent = new Intent(this, switchButtonListener.class); PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0); notificationView.setOnClickPendingIntent(R.id.closeOnFlash, pendingSwitchIntent); notificationManager.notify(1, notification);} public static class switchButtonListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("Here", "I am here"); FlashOnOff flashLight; flashLight = new FlashOnOff(); flashLight.flashLightOff(); flashLight.releaseCamera(); }}
and my xml:
<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="horizontal"android:weightSum="100" > <ImageView android: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" /><TextView android: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" /><Button android: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:
<receiver android:name="FlashLight$switchButtonListener" />
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。