Кнопки панели уведомлений Android не работают
Я занимаюсь разработкой музыкального плеера. Я создал панель уведомлений для управления музыкой после выхода из приложения. У меня есть три кнопки (воспроизведение, пауза, закрытие) в моем уведомлении. Мое уведомление работало гладко на 2.3 ОС. Уведомление не работало в 2.3.6 . Я добавил эти коды в свой класс уведомлений, после чего notificaton начал работать.
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 1,
new Intent(), 0);
notification.contentIntent = contentIntent;
Но я не могу нажимать на кнопки. Потому что, когда я нажимаю на него, выберите все панели уведомлений. Как я могу включить мои кнопки?
Это мой класс уведомлений;
открытый класс MyNotification расширяет Notification {
public static RemoteViews contentView;
private Context ctx;
public static NotificationManager mNotificationManager;
public static Notification notification;
public MyNotification(Context ctx){
super();
this.ctx=ctx;
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
CharSequence tickerText = "Bando";
long when = System.currentTimeMillis();
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
notification=builder.getNotification();
notification.when=when;
notification.tickerText=tickerText;
notification.icon=R.drawable.icon;
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 1,
new Intent(), 0);
contentView=new RemoteViews(ctx.getPackageName(), R.layout.notification_layout);
//set the button listeners
setListeners(contentView);
notification.contentView = contentView;
notification.flags |= Notification.FLAG_NO_CLEAR;
// used to call up this specific intent when you click on the notification
notification.contentIntent = contentIntent;
CharSequence contentTitle = "From Shortcuts";
mNotificationManager.notify(548853, notification);
}
public void setListeners(RemoteViews view){
//TODO screencapture listener
//adb shell /system/bin/screencap -p storage/sdcard0/SimpleAndroidTest/test.png
view.setTextViewText(R.id.radioname,MainActivity.rs.radioName);
Intent radio=new Intent(ctx, HelperActivity.class);
radio.putExtra("DO", "play");
radio.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pRadio = PendingIntent.getActivity(ctx, 0, radio, PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.play, pRadio);
//TODO screen size listener
Intent volume=new Intent(ctx, HelperActivity.class);
volume.putExtra("DO", "pause");
volume.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pVolume = PendingIntent.getActivity(ctx, 1, volume, PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.pause, pVolume);
//top listener
Intent top=new Intent(ctx, HelperActivity.class);
top.putExtra("DO", "close");
top.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pTop = PendingIntent.getActivity(ctx, 3, top, PendingIntent.FLAG_CANCEL_CURRENT);
view.setOnClickPendingIntent(R.id.close, pTop);
//app listener
Intent app=new Intent(ctx, HelperActivity.class);
app.putExtra("DO", "app");
PendingIntent pApp = PendingIntent.getActivity(ctx, 4, app, 0);
view.setOnClickPendingIntent(R.id.app, pApp);
}
}
И это мой Xml-код макета уведомлений;
//Xml Code of notification layout ;
Xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lmain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/lmain1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/app"
style="?android:attr/buttonStyleSmall"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/nlogo" />
<LinearLayout
android:id="@+id/lay1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="0.77"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/la1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/play" />
<ImageButton
android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:background="@drawable/pause" />
</LinearLayout>
<!-- Button
android:id="@+id/sms"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sms" />
<Button
android:id="@+id/tel"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel" /-->
<LinearLayout
android:id="@+id/la2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/radioname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="Deneme"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
style="?android:attr/buttonStyleSmall"
android:background="@drawable/nclose1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>