I'm trying to build a notification and receive it after an interval of time.
Here's how:
futureInMillis = SystemClock.elapsedRealtime() + 176000;
Intent notificationIntent = new Intent(getBaseContext(), NotificationG.class);
notificationIntent.putExtra(NotificationG.NOTIFICATION, getNotification());
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), m, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
Here's NotificationG.class
:
public class NotificationG extends BroadcastReceiver {
public static String NOTIFICATION = "notification_gatsp";
public static NotificationManager mNotifyMgr;
@Override
public void onReceive(Context context, Intent intent) {
mNotifyMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
Notification notification = intent.getParcelableExtra(NOTIFICATION);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
mNotifyMgr.notify(5, notification);
}
}
Here's is getNotification()
method:
public Notification getNotification() {
icon = BitmapFactory.decodeResource(getBaseContext().getResources(),
R.drawable.app_icon_1);
mBuilder =
new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.mipmap.app_icon_1)
.setContentTitle("title")
.setLargeIcon(icon)
.setStyle(new NotificationCompat.BigTextStyle().bigText(""))
.setContentText("");
Intent resultIntent = new Intent(getBaseContext(), ARequest.class);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
resultIntent.putExtra("text", text);
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
getBaseContext(),
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(resultPendingIntent);
return mBuilder.build();
}
but I'm not receiving any notification instead this error: E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 9448080)
is getting printed out.
What's happening here and how can I fix it?
Please let me know.
I figured out the problem here and it was with the small icon of notification. It was exceeding the binder limit.
The same icon was saved in my mipmap
folder too and changing the reference from R.drawable.app_icon_1
to R.mipmap.app_icon_1
did the job for me.
I changed this line:
icon = BitmapFactory.decodeResource(getBaseContext().getResources(),
R.drawable.app_icon_1);
with this:
icon = BitmapFactory.decodeResource(getBaseContext().getResources(),
R.mipmap.app_icon_1);
and now there is no more error.