开发者

Custom Notification layout in X10

I'm using a custom notification layout in my app. It works fine in all other devices but not in Sony Xperia series. There the notifications doesn't show up.

Example:

When using setLatestEventInfo() and making a standard Notification, it works correctly. But when I use a custom layout it doesn't work on Sony Xperia series mobiles.

Code for the notification:

String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.customlayout);
    int icon = R.drawable.icon;
    CharSequence tickerText = "testing";
    Intent intent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(NotificationTest.this, 0, intent, 0);

    long when = System.currentTimeMillis(); 

    Notification mNotification = new Notification(icon, tickerText, when);
    mNotification.contentIntent = contentIntent;
    mNotification.flags = Notification.FLAG_AUTO_CANCEL;

    contentView.setTextViewText(R.id.title, tickerText);                
    mNotification.contentView = contentView;

    mNotificationManager.notify(0, mNotification);

This code above works perfectly on other devices, but Xperia series have problems

Any ideas?

EDIT: Standard custom layout from Android develo开发者_StackOverflow社区per's guide.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="3dp"
          >
<ImageView android:id="@+id/icon"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_marginRight="10dp"
          />
<TextView android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:textColor="#000"
          />
 </LinearLayout>


Well, this sounds like an Xperia bug. My guess is that Sony made some mods that assume a certain structure for the notification drawer content and it's failing. There might be LogCat messages to that effect.

If you have access to the device for testing, one thing you could try is to copy status_bar_latest_event_content.xml from the proper platform in your SDK into your project, and try using it. That is the standard Notification layout for the RemoteViews, if you don't override it.

If it succeeds, then my theory above is probably correct, and you can incrementally adjust that layout until it stops working, in which case you know what Sony's dependency is and can try to figure out how to work around it.

If you try the layout and it fails with the same symptoms, then Sony perhaps broke the whole notion of custom notification layouts. In that case, short of using Build to identify failing devices and working around them, you may need to stick to standard layouts.


This bug seems to be fixed on the latest versions to come of the firmware for Sony Ericsson Xperia devices. However, to ensure that we are looking at the same thing, it would be of great help if you could provide us with the LogCat verbose logs, please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜