0

Im trying to make my custom notification similar to this one enter image description here I found a bunch of similar questions here on SO and examples on the internet but no one helped me.

Here is my code:

        RemoteViews bigView = new RemoteViews(mContext.getApplicationContext().getPackageName(), R.layout.notification_playback);

        Intent i = new Intent(MainActivity.ACTION_PLAYER, null, mContext, MainActivity.class);
        i.putExtra("CURRENT_TRACK", t);
        i.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pi = PendingIntent.getActivity(mContext, 0, i, 0);

        Notification n = new NotificationCompat.Builder(mContext)
            .setContentTitle(t.getName())
            .setContentText(t.getArtistName())
            .setContentIntent(pi)
            .setSmallIcon(R.drawable.ic_notification)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher))
            .setOngoing(true)
            .setContent(bigView)
            .setWhen(System.currentTimeMillis())
            .build();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            n.bigContentView = bigView;

        NotificationManager notifyMgr = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        notifyMgr.notify(0, n);

It appears in default size and become a size I expect only after long tap on it.

Is it possible to make it a big size immediately without long tap ? And how can I do it if so ? Thanks!

oleg.semen
  • 2,901
  • 2
  • 28
  • 56
  • Here's [another question](http://stackoverflow.com/questions/21237495/create-custom-big-notifications) that may help you. – B W Oct 29 '14 at 13:20
  • @TheRealBenjamin thanks, but I already tried it. It says `The trick is not to use setStyle() but manually set the bigContentView field of the Notification after building it` but as you can see I'm doing right this. – oleg.semen Oct 29 '14 at 13:25
  • 1
    http://stackoverflow.com/questions/18367631/change-notification-layout – Praveena Oct 29 '14 at 13:29

1 Answers1

0

So, what i figured out. Notification appears expanded if it is it the to of notifications. Otherwise it appears wit regular height an user can drag it down to expand. In order to make it appear in the top of notifications you can use .setPriority(Notification.PRIORITY_MAX) in Builder.

oleg.semen
  • 2,901
  • 2
  • 28
  • 56
  • BTW if you do not set priority and device is plugged to your PC the most probably that `Connected as a media device` notification will be in the top so you will always see it as not expanded. – oleg.semen Oct 30 '14 at 17:46