Hey everyone,
The requirement was to make a custom notification since the android's
default notification only allows for an image. So I went through on how to
attach a custom UI for notification when expanded, the ready answer was to
create a custom view and pass to the notification manager and allowed from
API level 16.
So I did one and here the my layout xml code - filename:
notification_custom_view_new:
http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/GhostWhite;>
The way I referenced it in code:
private RemoteViews assignRemote(Bitmap bitmap, String title, String message
){
RemoteViews expandedView = new RemoteViews(Application.getInstance().
getPackageName(), R.layout.notification_custom_view_new);
expandedView.setTextViewText(R.id.title, title);
expandedView.setTextViewText(R.id.message, message); expandedView.
setImageViewBitmap(R.id.big_picture, bitmap);
expandedView.setImageViewResource(R.id.big_icon, R.mipmap.ic_launcher);
expandedView.setTextViewText(R.id.time, getOnlyHrsMin());
return expandedView;
}
assigning customview to notification manager:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notification.bigContentView = assignRemote(bitmap, title, message);
}
But this gave me error saying bad notification, I have identified over 15+
same question here on stackoverflow without a right answer.. Some suggest
it to be a resource missing and hence the error. I am sure from my end none
of the values are null nor resources missing errors are not there in my
remote view that is passed.
Any help will be appreciated and also I have tried for around a couple of
days to track the error but nothing good seems to happen. Please help me!
Screenshot attached for layout UI.. also find the NotificatioUtils and
layout xml files attached for reference.
Thanks
DJphy
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/1cc8ccad-f636-4558-9be8-5a83d5598012%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
notification_custom_view_new.xml
Description: XML document
package com.goldadorn.main.dj.support.gcm;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v7.app.NotificationCompat;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
import android.widget.RemoteViews;
import com.goldadorn.main.R;
import com.goldadorn.main.activities.Application;
import com.goldadorn.main.dj.utils.Constants;
import com.goldadorn.main.dj.utils.DateTimeUtils;
import com.goldadorn.main.dj.utils.IntentKeys;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* Created by COMP on 2/25/2016.
*/
public class NotificationUtils {
private static String TAG = NotificationUtils.class.getSimpleName();
private static Context mContext;
public NotificationUtils() {
}
public NotificationUtils(Context mContext) {
this.mContext = mContext;
}
public void showNotificationMessage(String title, String message, String timeStamp, Intent intent) {
showNotificationMessage(title, message, timeStamp, intent, null);
}
public void showNotificationMessage(final String title, final String message, final String timeStamp, Intent intent, String imageUrl) {
// Check for empty push message
if (TextUtils.isEmpty(message))
return;
// notification icon
final int icon = R.mipmap.ic_launcher;
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(IntentKeys.PUSH_NOTIFICATION_CALL, Constants.GCM_CALL);
final PendingIntent