I am implementing custom push notification by integrating RemoteViews
.The problem is,the buttons within the remoteview is not displaying.I am not getting what wrong I have done.
Code:
public class AlarmReceiver extends BroadcastReceiver {
Bitmap bannerimage;
private static int MY_NOTIFICATION_ID=1;
NotificationManager notificationManager;
Notification myNotification;
@SuppressLint("NewApi")
@Override
public void onReceive(Context context, Intent intent) {
bannerimage = BitmapFactory.decodeResource(context.getResources(),
R.drawable.dummyturkey);
MY_NOTIFICATION_ID=1;
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.custom_push_layout);
Intent myIntent = new Intent(context,DoSomething.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
MY_NOTIFICATION_ID,
myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
System.out.println("Alarm fired AlarmReciever:"+mydate);
remoteViews.setImageViewBitmap(R.id.imgbanner,bannerimage);
Notification myNotification = new Notification.Builder(context)
.setContent(remoteViews)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setSound(alarmSound)
.setAutoCancel(false).build();
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
}
The XML File custom_push_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="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgbanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@drawable/ic_launcher"
android:scaleType="fitXY" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This chicken has send you a friend request" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btnaccept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accept" />
<Button
android:id="@+id/btncancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btnaccept"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
The notification is coming,but it is only displaying the imageview and not the buttons or the textview within the layout.
Please give the solution with reference to the above code only,i.e. what wrong I am doing or what I am missing.Please dont post a fresh code.