마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

뮤직앱처럼 Notification에 있는 버튼의 배경은 어떻게 바꾸나요?

0 추천
public static void showNotify(Service $context)</span>
  {
    Resources res = $context.getResources();
    
    Intent playInent = new Intent($context, MainService.class);
    playInent.setAction("play");
    PendingIntent playPendingIntent = PendingIntent.getService($context, 0, playInent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent prevIntent = new Intent($context, MainService.class);
    prevIntent.setAction("prev");
    PendingIntent prevPendingIntent = PendingIntent.getService($context, 1, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent nextIntent = new Intent($context, MainService.class);
    nextIntent.setAction("next");
    PendingIntent nextPendingIntent = PendingIntent.getService($context, 2, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent offIntent = new Intent($context, MainService.class);
    offIntent.setAction("off");
    PendingIntent offPendingIntent = PendingIntent.getService($context, 3, offIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    RemoteViews remoteViews = new RemoteViews($context.getPackageName(), R.layout.noti_view);
    remoteViews.setOnClickPendingIntent(R.id.button1, playPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    RemoteViews bigView = new RemoteViews($context.getPackageName(), R.layout.noti_big_view);
    bigView.setOnClickPendingIntent(R.id.button1, playPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    NotificationCompat.Builder builder = new NotificationCompat.Builder($context).setSmallIcon(R.drawable.ic_launcher)
                                                                                 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
                                                                                 .setTicker(res.getString(R.string.app_name))
                                                                                 .setWhen(System.currentTimeMillis())
                                                                                 .setContentTitle(res.getString(R.string.app_name));
    
    builder.setContent(remoteViews);
    Notification notification = builder.build();
    
    notification.bigContentView = bigView;
    
//    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    $context.startForeground(ID_REMOTSERVICE, notification);
  }

 

  public static void pauseNotify(Service $context)
  {
    Resources res = $context.getResources();
    
    Intent playInent = new Intent($context, MainService.class);
    playInent.setAction("pause");
    PendingIntent playPendingIntent = PendingIntent.getService($context, 0, playInent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent prevIntent = new Intent($context, MainService.class);
    prevIntent.setAction("prev");
    PendingIntent prevPendingIntent = PendingIntent.getService($context, 1, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent nextIntent = new Intent($context, MainService.class);
    nextIntent.setAction("next");
    PendingIntent nextPendingIntent = PendingIntent.getService($context, 2, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent offIntent = new Intent($context, MainService.class);
    offIntent.setAction("off");
    PendingIntent offPendingIntent = PendingIntent.getService($context, 3, offIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    RemoteViews remoteViews = new RemoteViews($context.getPackageName(), R.layout.noti_view_pause);
    remoteViews.setOnClickPendingIntent(R.id.button1, playPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    RemoteViews bigView = new RemoteViews($context.getPackageName(), R.layout.noti_big_view_pause);
    bigView.setOnClickPendingIntent(R.id.button1, playPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    bigView.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    NotificationCompat.Builder builder = new NotificationCompat.Builder($context).setSmallIcon(R.drawable.ic_launcher)
                                                                                 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
                                                                                 .setTicker(res.getString(R.string.app_name))
                                                                                 .setWhen(System.currentTimeMillis())
                                                                                 .setContentTitle(res.getString(R.string.app_name));
    
    builder.setContent(remoteViews);
    Notification notification = builder.build();
    notification.bigContentView = bigView;
    
//    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    $context.startForeground(ID_REMOTSERVICE, notification);
  }

재생 버튼을 누르면 일시 멈춤으로 바뀌는게 깜빡임 없이 그냥 되는데, 제 소스에서는 반짝하면서 나와요. 

뮤직앱의 재생버튼 처럼 반짝거림 없이 바꾸려면 어떻게 해야하나요?

쎄미 (162,410 포인트) 님이 2014년 4월 28일 질문

1개의 답변

+1 추천
 
채택된 답변

이리저리 해보다가 겨우 해결했네요

 

public class NotifyUtil
{
  private final static int ID_REMOTSERVICE = 1;
  private RemoteViews _smallView, _bigView;
  private Notification _notification;
  private Intent _playIntent;
  private PendingIntent _playPendingIntent;
  
  
  public NotifyUtil(Service $context)
  {
    _playIntent = new Intent($context, MainService.class);
    _playIntent.setAction("play");
    _playPendingIntent = PendingIntent.getService($context, 0, _playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent prevIntent = new Intent($context, MainService.class);
    prevIntent.setAction("prev");
    PendingIntent prevPendingIntent = PendingIntent.getService($context, 1, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent nextIntent = new Intent($context, MainService.class);
    nextIntent.setAction("next");
    PendingIntent nextPendingIntent = PendingIntent.getService($context, 2, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    Intent offIntent = new Intent($context, MainService.class);
    offIntent.setAction("off");
    PendingIntent offPendingIntent = PendingIntent.getService($context, 3, offIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    _smallView = new RemoteViews($context.getPackageName(), R.layout.noti_view);
    _smallView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    _smallView.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    _smallView.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    _smallView.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    _bigView = new RemoteViews($context.getPackageName(), R.layout.noti_big_view);
    _bigView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    _bigView.setOnClickPendingIntent(R.id.button2, prevPendingIntent);
    _bigView.setOnClickPendingIntent(R.id.button3, nextPendingIntent);
    _bigView.setOnClickPendingIntent(R.id.button4, offPendingIntent);
    
    Resources res = $context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder($context).setSmallIcon(R.drawable.ic_launcher)
                                                                                 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
                                                                                 .setTicker(res.getString(R.string.app_name))
                                                                                 .setContentTitle(res.getString(R.string.app_name));
    _notification = builder.build();
    _notification.contentView = _smallView;
    _notification.bigContentView = _bigView;
    _notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
  }
  
  
  public void showNotify(Service $context)
  {
    _smallView.setImageViewResource(R.id.button1, android.R.drawable.ic_media_play);
    _bigView.setImageViewResource(R.id.button1, android.R.drawable.ic_media_play);
    
    _playIntent.setAction("play");
    _playPendingIntent = PendingIntent.getService($context, 0, _playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    _smallView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    _bigView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    
    $context.startForeground(ID_REMOTSERVICE, _notification);
  }
  
  
  public void pauseNotify(Service $context)
  {
    _smallView.setImageViewResource(R.id.button1, android.R.drawable.ic_media_pause);
    _bigView.setImageViewResource(R.id.button1, android.R.drawable.ic_media_pause);
    
    _playIntent.setAction("pause");
    _playPendingIntent = PendingIntent.getService($context, 0, _playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    _smallView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    _bigView.setOnClickPendingIntent(R.id.button1, _playPendingIntent);
    
    $context.startForeground(ID_REMOTSERVICE, _notification);
  }
}

 

쎄미 (162,410 포인트) 님이 2014년 4월 29일 답변
...