Всем привет! Создаю свое уведомление
Файл разметрки:
<ImageView
android:id="@+id/notify_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/str_empty"
android:src="@drawable/icon_notify_config" />
<TextView
android:id="@+id/notify_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="@+id/notify_image"
android:singleLine="true"
android:textStyle="bold"
android:text="" />
<Button
android:id="@+id/btnBtnClearNotify"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/notify_title"
android:layout_marginRight="2dp"
android:gravity="center_vertical|center_horizontal"
android:text="@string/clear" />
<TextView
android:id="@+id/notify_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/notify_image"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_toLeftOf="@+id/btnBtnClearNotify"
android:layout_marginRight = "3dp"
android:singleLine="false"
android:text="" />
Код:
private void SetSrvcNotification(String title, String msg){
notifyMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(intent);
contentIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notify_view);
contentView.setTextViewText(R.id.notify_title, title);
contentView.setTextViewText(R.id.notify_text, msg);
contentView.setImageViewResource(R.id.notify_image, R.drawable.icon_notify_config);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this);
mBuilder.setSmallIcon(R.drawable.icon_notify_config);
mBuilder.setContentIntent(contentIntent);
notify = mBuilder.build();
notify.contentView = contentView;
notify.flags |= Notification.FLAG_NO_CLEAR;
notifyMgr.notify(NOTIFY_ID, notify);
}
Уведомление запускается из сервиса и висит постоянно в процессе его работы. Сервис в него выкидывает некую инфу о своем состоянии. Загвоздка в том что не получается назначить отдельный обработчик на кнопку btnBtnClearNotify. По нажатию на которой хотелось бы чистить строку notify_text. Т.е. чтобы, например, из обработчика слалось бы удведомление, которое сервис ловит и обновляет уведомление.
Подскажите как сделать (навесить отдельный обработчик на кнопку!). Сейчас что на кнопку кликаешь что на всё уведомление, результат один - старт родительской активности.