2013-10-14 94 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

我發現了異常。此becouse我使用自定義佈局與imageButton不支持舊設備(api級別< 11)。可能會有助於某人。

0

u能張貼你如何建立你的通知代碼?

您是否使用支持庫中的Builder?因爲這個也支持較低的API級別。也許你正在使用一個Notification/NotificationBuilder,它是在較低的API級別上可用的noch。

+0

我已更新帖子。我不使用Builder; – dooplaye

2

我已經得到了同樣的錯誤,但是這是由於

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

刪除此行解決了這個問題。

+0

yes remoteview不支持selectableitembackground。 –