我试图建立通知并在一段时间后收到通知。
以下是:
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);
此处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);
}
}
这里是getNotification()
方法:
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();
}
但是我没有收到任何通知,而是发出此错误:E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 9448080)
正在打印出来。
这里发生了什么,我该如何解决?
请告诉我。
答案 0 :(得分:0)
我在这里想出了问题,这是通知的小图标。它超过了活页夹限制。
同样的图标也保存在我的mipmap
文件夹中,将引用从R.drawable.app_icon_1
更改为R.mipmap.app_icon_1
为我完成了这项工作。
我更改了这一行:
icon = BitmapFactory.decodeResource(getBaseContext().getResources(),
R.drawable.app_icon_1);
用这个:
icon = BitmapFactory.decodeResource(getBaseContext().getResources(),
R.mipmap.app_icon_1);
现在没有更多的错误了。