Как отобразить уведомления игрока musi c с помощью библиотеки поддержки libs v25 - PullRequest
0 голосов
/ 26 января 2020

Я использую следующий код для отображения настраиваемого уведомления, но оно не отображается. Следующее взято из моего класса обслуживания. Воспроизведение успешно при нажатии на песню, все работает, но уведомление.

скомпилировать SDK версии 25 - мин SDK 21 - целевой SDK 25

private void updateNotification ( ) {

     //   try {

            // normal notif
            RemoteViews smallView = new RemoteViews ( getPackageName ( ), R.layout.notification );
            smallView.setTextViewText ( R.id.notification_song_name, currentSong.getTitle ( ) );
            smallView.setTextViewText ( R.id.notification_artist_name, currentSong.getArtist ( ) );
            // expanded notif
            RemoteViews expanedView = new RemoteViews ( getPackageName ( ), R.layout.notification_expanded );
            expanedView.setTextViewText ( R.id.notification_song_name, currentSong.getTitle ( ) );
            expanedView.setTextViewText ( R.id.notification_album_name, currentSong.getAlbum ( ) );
            expanedView.setTextViewText ( R.id.notification_artist_name, currentSong.getArtist ( ) );



            if ( PlayerConstants.SONG_PAUSED ) {
                smallView.setImageViewBitmap ( R.id.notification_play_pause_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.ic_play_arrow_black_24dp ) ).getBitmap ( ) );
                expanedView.setImageViewBitmap ( R.id.notification_play_pause_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.ic_play_arrow_black_24dp ) ).getBitmap ( ) );
            }

            else {
                smallView.setImageViewBitmap ( R.id.notification_play_pause_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.ic_pause_black_24dp ) ).getBitmap ( ) );
                expanedView.setImageViewBitmap ( R.id.notification_play_pause_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.ic_pause_black_24dp ) ).getBitmap ( ) );
            }

            if ( currentSong.getIsLiked ( this ) )
                expanedView.setImageViewBitmap ( R.id.notification_favorite_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.drawable.ic_favorite_red_24dp ) ).getBitmap ( ) );

            else
                expanedView.setImageViewBitmap ( R.id.notification_favorite_button, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.ic_favorite_border_black_24dp ) ).getBitmap ( ) );


            setListeners ( smallView );
            setListeners ( expanedView );


            Bitmap albumArt = AudioExtensionMethods.getBitMap ( getBaseContext ( ), currentSong.getAlbumArtLocation ( ) );
            if ( albumArt != null ) {
                smallView.setImageViewBitmap ( R.id.notification_album_art, albumArt );
                expanedView.setImageViewBitmap ( R.id.notification_album_art, albumArt );
            }

            else {
                smallView.setImageViewBitmap ( R.id.notification_album_art, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.unkown_album_art ) ).getBitmap ( ) );
                expanedView.setImageViewBitmap ( R.id.notification_album_art, ( (BitmapDrawable) getResources ( ).getDrawable ( R.mipmap.unkown_album_art ) ).getBitmap ( ) );
            }



            // create an ongoing notif
            NotificationCompat.Builder builder = new NotificationCompat.Builder ( this )
                .setContent ( smallView )
                .setSmallIcon ( R.mipmap.launcher_icon )
                .setOngoing ( true );

            // makes the notif dismissable when playback is paused
            if ( PlayerConstants.SONG_PAUSED ) {
                builder.setOngoing ( false );
            }



            if ( currentVersionSupportBigNotification ) {
                builder.setCustomBigContentView ( expanedView );
            }

            Intent nIntent = new Intent ( this, MainActivity.class );
            nIntent.putExtra ( "notificationIntent", true );
            nIntent.addFlags ( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP );
            PendingIntent pendingIntent = PendingIntent.getActivity ( this, 0, nIntent, PendingIntent.FLAG_UPDATE_CURRENT );
            builder.setContentIntent ( pendingIntent );

            // send the notification
            Notification build = builder.build ( );
            notificationManager = (NotificationManager) getSystemService ( NOTIFICATION_SERVICE );
            notificationManager.notify ( NOTIFICATION_ID, build );
     //   }

      //  catch (Exception ignored) {}
    }

Я понятия не имею, что происходит в Вот. Любая помощь будет оценена. PS Я не хочу обновлять свои библиотеки, потому что обновление приводит к сбою приложения, и я не могу go писать целые коды с нуля.

1 Ответ

0 голосов
/ 27 января 2020

Ничего себе. Забавно, как я это решил. Оказывается, что уведомления, наряду с виджетами, НЕ поддерживают темы или как вы это называете. Я использовал "attr / primaryColor" в макете уведомления, и изменение их на нормальные цветовые форматы решило проблему.

...