Добавление действия onClick для кнопки в уведомлении
Я пытаюсь добавить кнопку в уведомление, используя пользовательский макет. Мне удалось добавить макет и отобразить кнопку. Тем не менее, я до сих пор не могу найти способ добавить слушателя щелчка к кнопке. Вот соответствующий код у меня есть:
Коды для добавления настраиваемого макета уведомления:
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
CharSequence tickerText = "Quick Application Launcher";
long when = System.currentTimeMillis();
Notification.Builder builder = new Notification.Builder(ctx);
Notification notification=builder.getNotification();
notification.when=when;
notification.tickerText=tickerText;
notification.icon=R.drawable.ic_launcher;
RemoteViews contentView=new RemoteViews(ctx.getPackageName(), R.layout.custom_notification);
Intent volume=new Intent(ctx, NotifActivityHandler.class);
volume.putExtra("DO", "2");
PendingIntent pVolume = PendingIntent.getActivity(ctx, 1, volume, 0);
contentView.setOnClickPendingIntent(R.id.btn2, pVolume);
notification.contentView = contentView;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(2345345, notification);
Это код NotifActivityHandler:
public class NotifActivityHandler extends Activity {
private NotifActivityHandler ctx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ctx=this;
String action= (String)getIntent().getExtras().get("DO");
Log.i("LOG", "lauching action: " + action);
if(action.equals("1")){
} else if(action.equals("2")){
} else if(action.equals("config")){
Intent i = new Intent(NotifActivityHandler.this, ConfigActivity.class);
startActivity(i);
}
}
}
Приведенные выше коды не дают никакого журнала, даже если я поставлюLog.i
, Я не уверен, что с этим не так. Любая помощь приветствуется.
Обновить
Я проверил это на устройстве ICS.