Ich habe den folgenden Dienst, der die Benachrichtigung in meiner Anwendung zeigt, zeigt es bis jetzt gut, aber es behandelt nicht die Klickereignisse einige wie. Wie gehe ich mit diesen um?Benachrichtigung mit Schaltflächen behandelt keine Ereignisse
Anforderung: Ich möchte, dass diese Benachrichtigung angezeigt wird, solange das Video abgespielt wird. Ich hoffe, dass dies der richtige Weg ist.
public class CustomNotifications extends Service implements
INotificationService {
private static CustomNotifications instance;
private Context ctx;
private NotificationManager mNotificationManager;
private String start = "play";
private String stop = "stop";
private VideoCastManager mCastManager;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (null != intent) {
String action = intent.getAction();
if (action != null) {
if (action.equals(start)) {
} else if (action.equals(stop)) {
}
}
}
return 1;
}
public void startNofication(Activity activity, String text) {
ctx = this.getApplicationContext();
Intent resultIntent = new Intent(this, FullscreenActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this,
0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Media Cast").setTicker(text)
.setAutoCancel(false).setOngoing(true)
.setContentIntent(resultPendingIntent);
RemoteViews contentView = new RemoteViews(ctx.getPackageName(),
com.me.app.mediacast.R.layout.notification_layout);
contentView.setTextViewText(
com.me.app.mediacast.R.id.notifcation_label, text);
contentView.setImageViewResource(
com.me.app.mediacast.R.id.notification_button,
R.drawable.ic_av_play_dark);
// set the button listeners
setListeners(contentView);
mBuilder.setContent(contentView);
int mNotificationId = 001;
// NotificationManager mNotifyMgr = (NotificationManager) activity
// .getSystemService(activity.NOTIFICATION_SERVICE);
// mNotifyMgr.notify(mNotificationId, mBuilder.build());
startForeground(mNotificationId, mBuilder.build());
}
private void setListeners(RemoteViews contentView) {
Intent radio = new Intent(start);
radio.setPackage(getPackageName());
PendingIntent pRadio = PendingIntent.getActivity(this, 0, radio, 0);
contentView.setOnClickPendingIntent(
com.me.app.mediacast.R.id.notification_button, pRadio);
}
@Override
public boolean stopService() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean startService(String text) {
startNofication((Activity) ContentHelper.getCurrentActivity(), text);
return true;
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
try {
mCastManager = VideoCastManager.getInstance();
} catch (CastException e) {
e.printStackTrace();
}
mCastManager.setNottificationService(this);
mCastManager.startNotificationService();
}
}
Folgendes ist das Layout xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" >
<TextView
android:id="@+id/notifcation_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/btn1" />
<TextView
android:id="@+id/notifcation_subtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/notifcation_label" />
<ImageButton
android:id="@+id/notification_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:layout_marginRight="19dp" />
</RelativeLayout>
Ich versuche nur Griffe diesen Klick zu erhalten auch so, ich die Taste Toggle zeigen kann je nach Status der Anwendung zu pausieren oder zu spielen.
Vielen Dank im Voraus für dieses Aussehen.
Haben Sie versucht, Antworten auf http://stackoverflow.com/questions/21872022/notification-for-android-music-player und http://stackoverflow.com/questions/24436977/play-pause-taste-bild-in-benachrichtigung-android? –