2014-11-20 4 views
0

질문이 있습니다. 클릭하면 '재생'이미지로 '일시 중지'변경 알림을 업데이트하고 싶습니다. 그러나 나는이 오류가 계속 :알림 이미지를 변경하는 중에 오류가 발생했습니다.

android.app.RemoteServiceException: Bad notification posted from package m.com.musicbox: Couldn't expand RemoteViews for:StatusBarNotification(pkg=m.com.musicbox user=UserHandle{0} id=522 tag=null score=0: Notification(pri=0 icon=7f020067 contentView=m.com.musicbox/0x7f03003d vibrate=null sound=null defaults=0x0 flags=0x2 when=1416463928948 ledARGB=0x0 contentIntent=Y deleteIntent=N contentTitle=N contentText=N tickerText=N kind=[null])) 

RemoteView, NotificationManagerNotification, 나는 업데이트 이전과 동일하게 사용하고 있습니다. 이 솔루션을 찾으려고 시도하기 때문에 이것이 올바른지 확실하지 않습니다. 희망은 누구든지 도울 수 있습니다.

void updateNotification() { 

    if (Utils.isStatus.equalsIgnoreCase("pause")) { 
     notificationView.setImageViewResource(R.id.play, R.drawable.ic_pause); 
    } else { 
     notificationView.setImageViewResource(R.id.play, R.drawable.ic_play); 
    } 
    notificationManager.notify(id, notification); 
} 


public void setNotification() { 
    String ns = Context.NOTIFICATION_SERVICE; 
    notificationManager = (NotificationManager) getSystemService(ns); 

    notification = new Notification(R.drawable.ic_launcher, null, 
      System.currentTimeMillis()); 

    notificationView = new RemoteViews(getPackageName(), 
      R.layout.notification_bar); 

    Intent notificationIntent = new Intent(context, Player.class); 
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
      this, 0, notificationIntent, 0); 

    notification.contentView = notificationView; 
    notification.contentIntent = pendingNotificationIntent; 
    notification.flags |= Notification.FLAG_ONGOING_EVENT; 

    Intent intentPlay = new Intent("m.com.musicbox.ACTION_PLAY"); 
    PendingIntent pendingPlayIntent = PendingIntent.getBroadcast(context, 
      100, intentPlay, 0); 

    Intent intentPrev = new Intent("m.com.musicbox.ACTION_PREVIOUS"); 
    PendingIntent pendingPrevIntent = PendingIntent.getBroadcast(context, 
      100, intentPrev, 0); 

    Intent intentNext = new Intent("m.com.musicbox.ACTION_NEXT"); 
    PendingIntent pendingNextIntent = PendingIntent.getBroadcast(context, 
      100, intentNext, 0); 

    Intent intentClose = new Intent("m.com.musicbox.ACTION_CLOSE"); 
    PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(context, 
      100, intentClose, 0); 

    notificationView.setOnClickPendingIntent(R.id.play, pendingPlayIntent); 
    notificationView.setOnClickPendingIntent(R.id.prev, pendingPrevIntent); 
    notificationView.setOnClickPendingIntent(R.id.next, pendingNextIntent); 
    notificationView 
      .setOnClickPendingIntent(R.id.close, pendingCloseIntent); 

    notificationManager.notify(id, notification); 

} 
+0

방금이 같은 노력 않았다 "notification.icon = R.drawable.icon;" – JRowan

답변

1

당신은 다음과 같이 수행해야합니다 : 다음은 내 코드입니다

void updateNotification() { 

    Notification notification; 
    long when = System.currentTimeMillis(); 

    if (Utils.isStatus.equalsIgnoreCase("pause")) { 
     notification = new Notification(R.drawable.pause, "String message", when); 
    } else { 
     notification = new Notification(R.drawable.play, "String message", when); 
    } 
    notificationManager.notify(id, notification); 
} 
+0

맞춤 레이아웃을 사용 중입니다. 이미지를 클릭 할 때이를 변경하고 싶습니다. 원본 이미지의 참조가 필요하므로 메서드를 사용할 수 없다고 생각합니다. 알림을 설정하는 방법에 대한 코드를 업데이트했습니다. – lily

관련 문제