Reputation: 617
I was working in android Custom Notifications, for that I designed Custom Layout. but when I got notification Some part of this layout was not showing. please check the screen shot of Notification
please some one suggest me how to use custom layouts for Notifications.how ever My code was like below.
my actual custom layout code was
<?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="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/notificationHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/startedVideoStreaming"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:background="@color/silvercolor"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:id="@+id/pauseId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="pause"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#000" />
<TextView
android:id="@+id/stopLiveId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="StopLive"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#000" />
</LinearLayout>
</LinearLayout>
and my android code was
private void showForegroundNotification() {
RemoteViews contentLayout = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentLayout.setTextViewText(R.id.notificationHeader, getString(R.string.startedVideoStreaming));
contentLayout.setTextViewText(R.id.pauseId, "Pause");
contentLayout.setTextViewText(R.id.stopLiveId, "StopLive");
final NotificationManager notifyManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Intent to call our activity from background.
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// The PendingIntent to launch our activity if the user selects this notification.
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification = null;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification.Builder(getApplicationContext())
.setContent(contentLayout)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setLights(Color.WHITE, 500, 500)
.build();
}
notification.flags = Notification.FLAG_NO_CLEAR;
notifyManager.notify(STREAMER_NOTIFICATION_ID, notification);
}
please some one help to get out of this situation
Upvotes: 0
Views: 1494
Reputation: 485
with this current code, remove the following line from your code
.setContent(contentLayout)
add the line above when You set the flag
notification.bigContentView = contentLayout;
notification.flags = Notification.FLAG_NO_CLEAR;
Upvotes: 1