2015-01-11 14 views
6

To pytanie zostało zadane wcześniej, ale żadna z odpowiedzi nie pomogła mi w opublikowaniu mojej sprawy.Nie można rozszerzyć RemoteViews dla: StatusBarNotification

Próbuję utworzyć niestandardowe powiadomienie przy użyciu pliku układu. Ale pojawia się błąd:

android.app.RemoteServiceException: Bad notification posted from package com.eswaraj.app.eswaraj: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.eswaraj.app.eswaraj user=UserHandle{0} id=8888 tag=null score=0: Notification(pri=0 contentView=com.eswaraj.app.eswaraj/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null]))

Mój plik układ jest

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="left"> 

<com.makeramen.RoundedImageView 
    android:id="@+id/nImage" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:src="@drawable/profile_image" 
    android:padding="15dp" 
    android:scaleType="fitCenter" 
    app:riv_corner_radius="30dip" 
    app:riv_border_width="2dip" 
    app:riv_border_color="#333333" 
    app:riv_mutate_background="true" 
    app:riv_oval="true"/> 

<TextView 
    android:id="@+id/nTitle" 
    android:text="eSwaraj: Your voice is heard" 
    android:layout_toRightOf="@+id/nImage" 
    android:paddingTop="12dp" 
    android:textSize="20dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/nMessage" 
    android:layout_below="@+id/nTitle" 
    android:layout_toRightOf="@+id/nImage" 
    android:text="Your comaplaint viewed" 
    android:textSize="15dp" 
    android:paddingTop="5dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/nTime" 
    android:layout_toRightOf="@+id/nImage" 
    android:layout_below="@+id/nMessage" 
    android:textSize="13dp" 
    android:paddingTop="5dp" 
    android:text="12:23PM" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</RelativeLayout> 

A ja wysyłając zgłoszenie następująco:

public void sendNotification(Context caller, Class<?> activityToLaunch, Bitmap icon, GcmMessageDto gcmMessageDto, int id) { 
     Intent toLaunch; 
     RemoteViews remoteViews = new RemoteViews(caller.getPackageName(), R.layout.notification); 
     if(activityToLaunch != null) { 
      toLaunch = new Intent(caller, activityToLaunch); 
     } 
     else { 
      toLaunch = new Intent(); 
     } 
     PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0); 

     NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE); 
     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(caller) 
        .setSmallIcon(android.R.drawable.ic_notification_overlay) 
        .setContentIntent(intentBack); 

     remoteViews.setTextViewText(R.id.nMessage, gcmMessageDto.getMessage()); 
     remoteViews.setTextViewText(R.id.nTime, new Date().toString()); 
     if(icon != null) { 
      remoteViews.setImageViewBitmap(R.id.nImage, icon); 
     } 
     mBuilder.setContent(remoteViews); 

     notifier.notify(id, mBuilder.build()); 
    } 

Każda pomoc będzie mile widziane.

Odpowiedz

14

Krótko mówiąc,

com.makeramen.RoundedImageView

jest brudząc ze swojej pracy.

Nie wszystkie widoki mogą być używane w widokach zdalnych, które służą do tworzenia niestandardowych powiadomień. Według this official page tylko następujące mogą być używane do tworzenia RemoteViews:

  • FrameLayout
  • LinearLayout
  • RelativeLayout
  • GridLayout
  • AnalogClock
  • Przycisk
  • chronometr
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView
  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper

Więc trzeba znaleźć obejście do zmodyfikowanej klasy ImageView i użytkowania zamiast zwykłego ImageView.

+0

W moim przypadku użyłem 'AppCompatImageView'. Przejście do "ImageView" rozwiązało problem. – iTurki