Here is my code for notification:-
public void showNotification(String Name, String Rate, int Image_Source, int PandP, int Repeat) {
RemoteViews remoteview = new RemoteViews(getPackageName(), R.layout.notification_layout);
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SongsListActivity.class), 0);
notification = new NotificationCompat.Builder(this)
.setContent(remoteview)
.setPriority(2)
.setTicker(NameD.getText())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(NameD.getText())
.setContentText(RateD.getText())
.setContentIntent(pi)
.setAutoCancel(false)
.setCustomBigContentView(remoteview)
.build();
notification.bigContentView = remoteview;
remoteview.setImageViewResource(R.id.Repeat_N, Repeat);
remoteview.setImageViewResource(R.id.P_and_P_N, PandP);
remoteview.setTextViewText(R.id.Name_N, Name);
remoteview.setTextViewText(R.id.Rate_N, Rate);
remoteview.setImageViewResource(R.id.Image_N, Image_Source);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(111111, notification);
}
here is my xml of notification:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2196F3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#2196F3"
android:orientation="horizontal">
<ImageView
android:id="@+id/Image_N"
android:layout_width="100dp"
android:layout_height="100dp"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/Name_N"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold"
android:maxLength="25"/>
<TextView
android:id="@+id/Rate_N"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#F44336" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/Repeat_N"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ic_repeat_white_48dp"
android:background="#2196F3"/>
<ImageButton
android:id="@+id/Previous_N"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ic_skip_previous_white_48dp"
android:background="#2196F3"/>
<ImageButton
android:id="@+id/P_and_P_N"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ic_play_arrow_white_48dp"
android:background="#2196F3"/>
<ImageButton
android:id="@+id/Next_N"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ic_skip_next_white_48dp"
android:background="#2196F3"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Layout of my notification
now how do i add action to the 4 buttons in the notification so that:-
a) the Pause Imagebutton pauses the MediaPlayer mediaplayer and then change it image to play.
b) the next and previous Imagebuttons call a method mediaplayer(int i)
c) the Repet Imagebutton call a method changeRepeat()