Reputation: 1
I am trying to build a music player, for which I need to have music control in Notification tray. I am using RemoteViews for this But not able to add event listener for Play/Pause, Next and Previous. Below is the source code.
custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/gradient_background"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon_logo"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:src="@drawable/app_logo_notification"/>
<TextView android:id="@+id/lbl_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#b8a25e"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="TEST" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#b8a25e"
android:layout_marginLeft="20dp"
android:text="Now Playing James Bond anthem"/>
<ImageView
android:id="@+id/icon_previous"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:src="@drawable/icon_previous_home"/>
<ImageView
android:id="@+id/icon_play"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_action_playback_play"/>
<ImageView
android:id="@+id/icon_next"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:src="@drawable/icon_next_home"/>
</LinearLayout>
</LinearLayout>
Notification code -
var AppR = Ti.App.Android.R;
var customLayout = Ti.Android.createRemoteViews({
layoutId : AppR.layout.custom_layout
});
var notification = Titanium.Android.createNotification({
contentView : customLayout,
visibility : Titanium.Android.VISIBILITY_PUBLIC,
icon : AppR.drawable.app_logo_notification,
});
customLayout.setTextViewText(AppR.id.message, "Now Playing...\n");
customLayout.setImageViewResource(AppR.id.icon_play, AppR.drawable.ic_action_playback_pause);
var icon_play = AppR.id.icon_play;
Ti.Android.NotificationManager.notify(1, notification);
Any suggestions would be appreciated.
Upvotes: 0
Views: 83
Reputation: 4055
There is a full example of a RemoteView Notification at:
https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/android_notifications.html#AndroidNotifications-Customlayout
that features buttons and click events.
In your example it should be:
customLayout.setOnClickPendingIntent(Ti.App.Android.R.id.icon_play, onClickCallback);
function onClickCallback(){}
Upvotes: 0