嗨,我的应用程序 aacplayer 在我的 Galaxy s3 中运行良好,但在具有 android 2.3.4 的 Galaxy ace 中,我的应用程序崩溃了,但是如果我从代码中删除通知管理器,那么它可以完美运行。
这是我的通知管理器代码:
public void playerMetadata(final String key, final String value) {
TextView tv = null;
if ("StreamTitle".equals(key) || "icy-name".equals(key)
|| "icy-description".equals(key)) {
tv = txtMetaTitle;
} else if ("icy-url".equals(key)) {
tv = txtMetaUrl;
} else
return;
final TextView ftv = tv;
uiHandler.post(new Runnable() {
public void run() {
ftv.setText(value);
int NOTIFICATION_ID = 1;
String ns = Context.NOTIFICATION_SERVICE;
Context context = getApplicationContext();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.notificacion;
long when = System.currentTimeMillis();
CharSequence tickerText = "Reproduciendo...";
Notification notification = new Notification(icon, tickerText,
when);
RemoteViews contentView = new RemoteViews(getPackageName(),
R.layout.notification);
contentView.setImageViewResource(R.id.icon, R.drawable.notificacion);
contentView.setTextViewText(R.id.title_text, txtMetaTitle
.getText().toString());
contentView.setTextViewText(R.id.message_text, txtMetaUrl
.getText().toString());
notification.contentView = contentView;
Intent notificationIntent = new Intent(AACPlayerActivity.this,
Principal.class);
// Intent notificationIntent = new Intent(this,
// Principal.class);
PendingIntent contentIntent = PendingIntent.getActivity(
context, 0, notificationIntent, 0);
// PendingIntent contentIntent = PendingIntent.getActivity(this,
// 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
});
}
我不知道为什么在galaxy s3中效果很好,但在galaxy ace中效果不佳,我该如何解决。
非常感谢您。
编辑:
日志猫:
E/AndroidRuntime(16846): android.app.RemoteServiceException: Bad notification posted from package com.spoledge.aacplayer: Couldn't expand RemoteViews for: StatusBarNotification(package=com.spoledge.aacplayer id=1 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x2))
如果我在我的代码中添加这个:
notification.setLatestEventInfo(context,
txtMetaTitle.getText().toString(),
txtMetaUrl.getText().toString(), contentIntent);
通知效果很好,没有问题,但我需要显示通知:
contentView.setTextViewText(R.id.title_text, txtMetaTitle
.getText().toString());
contentView.setTextViewText(R.id.message_text, txtMetaUrl
.getText().toString());
该 txtmetatitle 字段有一个选取框,但如果添加在 notification.setLatestEvent 之前发布的那条行,则不会崩溃,但我无法使选取框正确运行