2013-10-14 4 views
1

. Я видел подобные вопросы, но не смог решить мою проблему. Я использую уведомление с пользовательским макетом. На моем устройстве (sdk 16) все в порядке, но на Android 2.3.7 мое приложение выкидывает ошибку. Вот мой макет.Не удалось развернуть RemoteViews android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:orientation="horizontal"> 
    <ImageView 
      android:id="@+id/notifAlbum" 
      android:maxWidth="80dip" 
      android:adjustViewBounds="false" 
      android:layout_width="70dp" 
      android:layout_height="70dp" 
      android:scaleType="fitCenter"/> 
    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center" 
      android:orientation="vertical" android:paddingLeft="10dp"> 
     <TextView 
       android:id="@+id/notifTitle" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:ellipsize="marquee" android:textSize="18sp" 
       android:textColor="@color/almost_white"/> 
     <TextView 
       android:id="@+id/notifArtist" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:ellipsize="marquee" android:textSize="14sp"/> 
    </LinearLayout> 
    <ImageButton 
      android:id="@+id/notifPrevious" 
      android:paddingTop="10dip" 
      android:paddingBottom="10dip" 
      android:layout_height="42dip" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center" 
      android:background="?android:attr/selectableItemBackground" 
      android:scaleType="fitCenter" 
      android:src="@drawable/widget_previous" android:baselineAlignBottom="false"/> 
    <ImageButton 
      android:id="@+id/notifPlay" 
      android:paddingTop="6dip" 
      android:paddingBottom="6dip" 
      android:layout_height="42dip" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center" 
      android:background="?android:attr/selectableItemBackground" 
      android:scaleType="fitCenter" 
      android:src="@drawable/widget_play" android:paddingLeft="6dp" android:paddingRight="6dp"/> 
    <ImageButton 
      android:id="@+id/notifNext" 
      android:paddingTop="10dip" 
      android:paddingBottom="10dip" 
      android:layout_height="42dip" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center" 
      android:background="?android:attr/selectableItemBackground" 
      android:scaleType="fitCenter" 
      android:src="@drawable/widget_next" android:longClickable="false"/> 
    <ImageButton 
      android:id="@+id/notifClose" 
      android:layout_height="42dip" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center" 
      android:background="?android:attr/selectableItemBackground" 
      android:scaleType="fitCenter" 
      android:src="@drawable/close" android:paddingRight="4dp" android:paddingLeft="2dp" 
      android:paddingTop="12dp" android:paddingBottom="12dp"/> 
</LinearLayout> 

Произошла ошибка.

android.app.RemoteServiceException: Bad notification posted from package com.perm.DoomPlay: Couldn't expand RemoteViews for: StatusBarNotification(package=com.perm.DoomPlay id=931 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x62)) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
.... 

вот как я построить уведомление

private RemoteViews getNotifViews(int layoutId) 
    { 
     RemoteViews views = new RemoteViews(getPackageName(), layoutId); 

     Audio audio = audios.get(indexCurrentTrack); 

     views.setTextViewText(R.id.notifTitle, audio.getTitle()); 
     views.setTextViewText(R.id.notifArtist, audio.getArtist()); 

     Bitmap cover = AlbumArtGetter.getBitmapById(audio.getAid(),this); 
     if (cover == null) 
     { 
      views.setImageViewBitmap(R.id.notifAlbum, BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover)); 
     } 
     else 
     { 
      views.setImageViewBitmap(R.id.notifAlbum, cover); 
     } 


     views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play); 

     ComponentName componentName = new ComponentName(this,PlayingService.class); 

     Intent intentPlay = new Intent(actionPlay); 
     intentPlay.setComponent(componentName); 
     views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0)); 

     Intent intentNext = new Intent(actionNext); 
     intentNext.setComponent(componentName); 
     views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0)); 

     Intent intentPrevious = new Intent(actionPrevious); 
     intentPrevious.setComponent(componentName); 
     views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0)); 

     Intent intentClose = new Intent(actionClose); 
     intentClose.setComponent(componentName); 
     views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0)); 

     return views; 
    } 

    private Notification createNotification() 
    { 

     Intent intentActivity; 


     intentActivity = new Intent(FullPlaybackActivity.actionReturnFull); 
     intentActivity.setClass(this,FullPlaybackActivity.class); 
     intentActivity.putExtra(FileSystemActivity.keyMusic,audios); 
     intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     Notification notification = new Notification(); 
     notification.contentView = getNotifViews(R.layout.notif); 
     notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; 
     notification.contentIntent = PendingIntent.getActivity(this,0,intentActivity,PendingIntent.FLAG_UPDATE_CURRENT); 
     notification.icon = isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play; 

     return notification; 
    } 

ответ

0

Я нашел исключение. Это потому, что я использую пользовательский макет с imageButton, который не поддерживается на старых устройствах (уровень api < 11). Может быть, это будет полезно для кого-то.

0

может у поста код, как вы строите свой Notification?

Вы используете Builder из библиотеки поддержки? Потому что это поддерживает и более низкий уровень API. Возможно, вы используете Notification/NotificationBuilder, который доступен на более низком уровне API.

+0

Я обновил сообщение. Я не использую Builder; – dooplaye

2

Я получил ту же ошибку, но это связано с

android:background="?android:attr/selectableItemBackground" 

Удаление этой линии решить эту проблему.

+0

да remoteview не поддерживает selectableitembackground. –

Смежные вопросы