Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Re: Notificação play music

Matheus, qual é o API level mínimo definido no seu manifest?

Em qua, 5 de ago de 2015 às 17:12, Matheus Henrique da Silva <matheustargaryen@gmail.com> escreveu:
Rudson, apesar de não ter dado tempo de eu olhar a sugestão do Francis (obrigado msm assim cara), eu implementei uma lógica que deu certo:
Foda-se o MediaSession, apenas coloque NotificationCompat.Action na sua notificação e intercepte-as através de um broadcastReceiver no service.

if (isPlaying) {

            mActionIntent
= new Intent(ACTION_NOTIFICATION_INTENT).putExtra(EXTRA_KEY_ACTION, EXTRA_ACTION_STOP);

            mPendingIntent
= PendingIntent.getBroadcast(mContext, 0, mActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            mNotificationAction
= new NotificationCompat.Action(R.drawable.ic_stop_white_48dp, "Parar", mPendingIntent);

            onGoing
= true;

       
} else {

            mActionIntent
= new Intent(ACTION_NOTIFICATION_INTENT).putExtra(EXTRA_KEY_ACTION, EXTRA_ACTION_PLAY);

            mPendingIntent
= PendingIntent.getBroadcast(mContext, 0, mActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            mNotificationAction
= new NotificationCompat.Action(R.drawable.ic_play_arrow_white_48dp, "Tocar", mPendingIntent);

            onGoing
= false;

       
}

        mNotification
= new NotificationCompat.Builder(mContext)
               
.setSmallIcon(R.drawable.ic_horse_notification)
               
.setContentTitle(mContext.getResources().getString(R.string.app_name))
               
.setContentText(StreamTitle)
               
.setContentIntent(resultPendingIntent)
               
.setOngoing(onGoing)
               
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg_sertaovibe))
               
.setStyle(new NotificationCompat.MediaStyle().setShowCancelButton(!onGoing).setShowActionsInCompactView(0))
               
.addAction(mNotificationAction)
               
.build();

EH NOIS VÉI!

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário