Search in sources :

Example 51 with Notification

use of android.app.Notification in project NotificationPeekPort by lzanita09.

the class NotificationHelper method getNotificationTextLines.

/**
     * Get multi-line text content from notification.
     *
     * @param n     StatusBarNotification object.
     * @return      Notification text.
     */
public static String getNotificationTextLines(StatusBarNotification n) {
    Notification notification = n.getNotification();
    CharSequence[] textLines = notification.extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
    StringBuffer buffer = new StringBuffer();
    if (textLines != null) {
        for (CharSequence line : textLines) {
            buffer.append(line);
            buffer.append('\n');
        }
    }
    return buffer.toString();
}
Also used : Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 52 with Notification

use of android.app.Notification in project howabout-android by recomio.

the class MusicPlayerService method play.

@SuppressWarnings("deprecation")
private void play(final String trackTitle, final String artistName, String thumbnailUrl) {
    Notification notification = new Notification(R.drawable.ic_launcher, trackTitle + " - " + artistName, System.currentTimeMillis());
    Intent intent = new Intent(this, MusicPlaylistActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, trackTitle, artistName, pendingIntent);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, notification);
    playlistAdapter.setCurrentLyrics("");
    isLoaded = false;
    isLoading = true;
    mediaPlayer.stop();
    mediaPlayer.reset();
    if (playInfoRequest != null) {
        contentManager.cancel(playInfoRequest);
        playInfoRequest = null;
    }
    playInfoRequest = new PlayInfoRequest(trackTitle, artistName);
    contentManager.execute(playInfoRequest, new RequestListener<PlayInfo>() {

        @Override
        public void onRequestFailure(SpiceException e) {
            if (groovesharkStreamUrlGetter != null) {
                groovesharkStreamUrlGetter.isStopped(true);
            }
            if (e instanceof RequestCancelledException) {
                return;
            }
            isLoading = false;
            playlistAdapter.playNext();
            playlistAdapter.notifyDataSetChanged();
            Toast.makeText(MusicPlayerService.this, trackTitle + "(" + artistName + ")" + "\n 무료 스트리밍 음원을 찾지 못했습니다.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRequestSuccess(final PlayInfo playInfo) {
            playlistAdapter.setCurrentLyrics(playInfo.getLyrics());
            Log.i("grooveshark", playInfo.getTrackTitle());
            final String groovesharkSongId = playInfo.getTinysongId();
            if (groovesharkSongId != null) {
                HowaboutApplication application = (HowaboutApplication) getApplicationContext();
                try {
                    groovesharkStreamUrlGetter = new GroovesharkStreamUrlGetter(application, groovesharkSongId, new OnGetGroovesharkStreamKey() {

                        @Override
                        public void sucess(String streamUrl) {
                            playInfo.setGroovesharkSongID(groovesharkSongId);
                            playInfo.setGroovesharkStreamUrl(streamUrl);
                            playStream(playInfo);
                        }

                        @Override
                        public void error(Exception e) {
                            playStream(playInfo);
                        }
                    });
                    groovesharkStreamUrlGetter.getGroovesharkStreamUrlAsync();
                } catch (Exception e) {
                    playStream(playInfo);
                }
            } else {
                playStream(playInfo);
            }
        }
    });
}
Also used : GroovesharkStreamUrlGetter(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HowaboutApplication(io.recom.howabout.HowaboutApplication) Notification(android.app.Notification) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) PlayInfo(io.recom.howabout.category.music.model.PlayInfo) PendingIntent(android.app.PendingIntent) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) OnGetGroovesharkStreamKey(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter.OnGetGroovesharkStreamKey) PlayInfoRequest(io.recom.howabout.category.music.net.PlayInfoRequest)

Example 53 with Notification

use of android.app.Notification in project robolectric by robolectric.

the class ShadowNotificationBuilderTest method build_addsActionToNotification.

@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void build_addsActionToNotification() throws Exception {
    PendingIntent action = PendingIntent.getBroadcast(RuntimeEnvironment.application, 0, null, 0);
    Notification notification = builder.addAction(0, "Action", action).build();
    assertThat(notification.actions[0].actionIntent).isEqualToComparingFieldByField(action);
}
Also used : PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 54 with Notification

use of android.app.Notification in project robolectric by robolectric.

the class ShadowNotificationBuilderTest method build_setsIconOnNotification.

@Test
@Config(minSdk = M)
public void build_setsIconOnNotification() throws Exception {
    Notification notification = builder.setSmallIcon(R.drawable.an_image).build();
    assertThat(notification.getSmallIcon().getResId()).isEqualTo(R.drawable.an_image);
}
Also used : Notification(android.app.Notification) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 55 with Notification

use of android.app.Notification in project robolectric by robolectric.

the class ShadowNotificationBuilderTest method build_setsUsesChronometerOnNotification_true.

@Test
@Config(minSdk = JELLY_BEAN_MR1)
public void build_setsUsesChronometerOnNotification_true() throws Exception {
    Notification notification = builder.setUsesChronometer(true).setWhen(10).setShowWhen(true).build();
    assertThat(shadowOf(notification).usesChronometer()).isTrue();
}
Also used : Notification(android.app.Notification) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

Notification (android.app.Notification)568 PendingIntent (android.app.PendingIntent)276 Intent (android.content.Intent)253 NotificationManager (android.app.NotificationManager)128 StatusBarNotification (android.service.notification.StatusBarNotification)96 NotificationCompat (android.support.v4.app.NotificationCompat)64 Resources (android.content.res.Resources)56 Bitmap (android.graphics.Bitmap)48 Test (org.junit.Test)48 Context (android.content.Context)47 ITransientNotification (android.app.ITransientNotification)32 RemoteViews (android.widget.RemoteViews)30 RemoteException (android.os.RemoteException)24 ApplicationInfo (android.content.pm.ApplicationInfo)17 UserHandle (android.os.UserHandle)17 Date (java.util.Date)16 Uri (android.net.Uri)15 Bundle (android.os.Bundle)15 ComponentName (android.content.ComponentName)13 File (java.io.File)13