Search in sources :

Example 16 with PendingIntent

use of android.app.PendingIntent in project goro by stanfy.

the class GoroActivity method notificationSample.

private void notificationSample() {
    Intent intent = GoroService.taskIntent(GoroActivity.this, QUEUE_REST, new PendingTask(counter++, QUEUE_REST));
    PendingIntent pendingIntent = PendingIntent.getService(GoroActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(1, new Notification.Builder(GoroActivity.this).setTicker("Click to post to REST").setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle("Click to post to REST").setContentText("Intent will be sent to the service").setContentIntent(pendingIntent).getNotification());
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 17 with PendingIntent

use of android.app.PendingIntent in project Shuttle by timusus.

the class BaseCastManager method onConnectionFailed.

/*
     * (non-Javadoc)
     * @see com.google.android.gms.GoogleApiClient.OnConnectionFailedListener#
     * onConnectionFailed(com.google.android.gms.common.ConnectionResult)
     */
@Override
public void onConnectionFailed(ConnectionResult result) {
    LOGD(TAG, "onConnectionFailed() reached, error code: " + result.getErrorCode() + ", reason: " + result.toString());
    disconnectDevice(mDestroyOnDisconnect, false, /* clearPersistentConnectionData */
    false);
    mConnectionSuspended = false;
    if (mMediaRouter != null) {
        mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
    }
    for (BaseCastConsumer consumer : mBaseCastConsumers) {
        consumer.onConnectionFailed(result);
    }
    PendingIntent pendingIntent = result.getResolution();
    if (pendingIntent != null) {
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            LOGE(TAG, "Failed to show recovery from the recoverable error", e);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Example 18 with PendingIntent

use of android.app.PendingIntent in project Shuttle by timusus.

the class VideoCastManager method getCastControllerPendingIntent.

/*
     * Returns a PendingIntent that can open the target activity for controlling the cast experience
     */
private PendingIntent getCastControllerPendingIntent() {
    try {
        Bundle mediaWrapper = Utils.mediaInfoToBundle(getRemoteMediaInformation());
        Intent contentIntent = new Intent(mContext, mTargetActivity);
        contentIntent.putExtra(VideoCastManager.EXTRA_MEDIA, mediaWrapper);
        return PendingIntent.getActivity(mContext, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "getCastControllerPendingIntent(): Failed to get the remote media information");
    }
    return null;
}
Also used : NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Example 19 with PendingIntent

use of android.app.PendingIntent in project Shuttle by timusus.

the class VideoCastManager method setUpMediaSession.

/*
     * Sets up the {@link MediaSessionCompat} for this application. It also handles the audio
     * focus.
     */
@SuppressLint("InlinedApi")
private void setUpMediaSession(final MediaInfo info) {
    if (!isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
        return;
    }
    if (mMediaSessionCompat == null) {
        ComponentName mediaEventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName());
        mMediaSessionCompat = new MediaSessionCompat(mContext, "TAG", mediaEventReceiver, null);
        mMediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mMediaSessionCompat.setActive(true);
        mMediaSessionCompat.setCallback(new MediaSessionCompat.Callback() {

            @Override
            public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
                KeyEvent keyEvent = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
                if (keyEvent != null && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE || keyEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY)) {
                    toggle();
                }
                return true;
            }

            @Override
            public void onPlay() {
                toggle();
            }

            @Override
            public void onPause() {
                toggle();
            }

            private void toggle() {
                try {
                    togglePlayback();
                } catch (CastException | TransientNetworkDisconnectionException | NoConnectionException e) {
                    LOGE(TAG, "MediaSessionCompat.Callback(): Failed to toggle playback", e);
                }
            }
        });
    }
    mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
    PendingIntent pi = getCastControllerPendingIntent();
    if (pi != null) {
        mMediaSessionCompat.setSessionActivity(pi);
    }
    if (info == null) {
        mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder().setState(PlaybackStateCompat.STATE_NONE, 0, 1.0f).build());
    } else {
        mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder().setState(PlaybackStateCompat.STATE_PLAYING, 0, 1.0f).setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE).build());
    }
    // Update the media session's image
    updateLockScreenImage(info);
    // update the media session's metadata
    updateMediaSessionMetadata();
    mMediaRouter.setMediaSessionCompat(mMediaSessionCompat);
}
Also used : KeyEvent(android.view.KeyEvent) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) VideoIntentReceiver(com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver) SuppressLint(android.annotation.SuppressLint)

Example 20 with PendingIntent

use of android.app.PendingIntent in project Shuttle by timusus.

the class VideoCastManager method updateMediaSession.

/*
     * Updates the playback status of the Media Session
     */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateMediaSession(boolean playing) {
    if (!isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
        return;
    }
    if (!isConnected()) {
        return;
    }
    try {
        if ((mMediaSessionCompat == null) && playing) {
            setUpMediaSession(getRemoteMediaInformation());
        }
        if (mMediaSessionCompat != null) {
            int playState = isRemoteStreamLive() ? PlaybackStateCompat.STATE_BUFFERING : PlaybackStateCompat.STATE_PLAYING;
            int state = playing ? playState : PlaybackStateCompat.STATE_PAUSED;
            PendingIntent pi = getCastControllerPendingIntent();
            if (pi != null) {
                mMediaSessionCompat.setSessionActivity(pi);
            }
            mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder().setState(state, 0, 1.0f).setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE).build());
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to set up MediaSessionCompat due to network issues", e);
    }
}
Also used : NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) PendingIntent(android.app.PendingIntent) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Aggregations

PendingIntent (android.app.PendingIntent)1243 Intent (android.content.Intent)1043 Notification (android.app.Notification)233 NotificationCompat (android.support.v4.app.NotificationCompat)184 NotificationManager (android.app.NotificationManager)160 AlarmManager (android.app.AlarmManager)153 Bundle (android.os.Bundle)78 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)63 Bitmap (android.graphics.Bitmap)62 Context (android.content.Context)59 ComponentName (android.content.ComponentName)56 Uri (android.net.Uri)45 Test (org.junit.Test)44 IntentFilter (android.content.IntentFilter)43 SharedPreferences (android.content.SharedPreferences)38 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)34 UserHandle (android.os.UserHandle)31 IOException (java.io.IOException)30