2015-01-11 30 views
6

この質問は以前に尋ねられましたが、私のケースを投稿するのに役立たなかった回答はありませんでした。RemoteViewsを展開できませんでした:StatusBarNotification

レイアウトファイルを使用してカスタム通知を作成しようとしています。しかし、私はエラーを取得する:

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]))

は私のレイアウトファイルは

<?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> 

されており、次のように私は通知を送信しています:

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()); 
    } 

を任意の助けをいただければ幸いです。

答えて

14

がまもなく入れ、

com.makeramen.RoundedImageView

はあなたの仕事をいじりされます。

カスタム通知の作成に使用されるRemoteViewでは、一部のビューを使用できない場合があります。 this official pageによると、唯一の次は、RemoteViewsを作成するために使用することができます。

  • でframeLayout
  • のLinearLayout
  • RelativeLayout
  • のGridLayout
  • AnalogClock
  • ボタン
  • クロノ
  • のImageButton
  • ImageViewの
  • プログレス
  • のTextView
  • ViewFlipper
  • のListView
  • GridViewの
  • StackView
  • あなたが修正ImageViewのクラスおよび使用するための回避策を見つけなければならないので、

AdapterViewFlipper代わりにプレーンImageView。

+0

私の場合、私は 'AppCompatImageView'を使っていました。 'ImageView'への切り替えは、この問題を解決しました。 – iTurki

関連する問題