我有这段代码,
try {
if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
// app is in foreground, broadcast the push message
Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
pushNotification.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
// play notification sound
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.playNotificationSound();
} else {
// If the app is in background, firebase itself handles the notification
}
}
catch (Exception ex)
{
Toast.makeText(getApplicationContext(),ex.getMessage(), Toast.LENGTH_LONG).show();
}
它运行得很好,但是当它收到此行的通知时,应用程序突然崩溃了:
LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
永远不会输入catch异常! 我可以在logcat中看到:
com.package.myapp E/MediaPlayer: error (1, -2147483648)