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());
}
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);
}
}
}
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;
}
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);
}
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);
}
}
Aggregations