List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private PendingIntent createOpenAppPendingIntent(final Bundle pushBundle, final Class<?> targetClass, final String campaignId, final int requestId, final String intentAction) { PendingIntent contentIntent = null;/* w ww .j av a 2 s. c o m*/ if (intentAction.equals(GCM_INTENT_ACTION)) { contentIntent = PendingIntent.getService(pinpointContext.getApplicationContext(), requestId, this.notificationIntent(pushBundle, campaignId, requestId, GCM_INTENT_ACTION, targetClass), PendingIntent.FLAG_ONE_SHOT); } else { contentIntent = PendingIntent.getBroadcast(pinpointContext.getApplicationContext(), requestId, this.notificationIntent(pushBundle, campaignId, requestId, FCM_INTENT_ACTION, targetClass), PendingIntent.FLAG_ONE_SHOT); PinpointNotificationReceiver.setNotificationClient(this); } return contentIntent; }
From source file:se.anyro.tagtider.TransferActivity.java
private void registerC2dm() { mProgressDialog.setMessage("Initierar bevakning..."); mProgressDialog.show();//from ww w . ja va 2 s.c om registerReceiver(mC2dmStatusReceiver, mC2dmRegisteredFilter); Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); registrationIntent.putExtra("sender", "tagtider@gmail.com"); startService(registrationIntent); }
From source file:com.notalenthack.blaster.CommandActivity.java
private void startStatusUpdate() { // Setup expiration if we never get a message from the service AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(); intent.setAction(Constants.ACTION_REFRESH_STATUS); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Set repeating updating of status, will need to cancel if activity is gone Calendar cal = Calendar.getInstance(); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Constants.UPATE_STATUS_PERIOD * 1000, pi); }
From source file:com.android.providers.downloads.DownloadService.java
/** * Update {@link #mDownloads} to match {@link DownloadProvider} state. * Depending on current download state it may enqueue {@link DownloadThread} * instances, request {@link DownloadScanner} scans, update user-visible * notifications, and/or schedule future actions with {@link AlarmManager}. * <p>//w w w . j a v a2 s. c o m * Should only be called from {@link #mUpdateThread} as after being * requested through {@link #enqueueUpdate()}. * * @return If there are active tasks being processed, as of the database * snapshot taken in this update. */ private boolean updateLocked() { final long now = mSystemFacade.currentTimeMillis(); boolean isActive = false; long nextActionMillis = Long.MAX_VALUE; final Set<Long> staleIds = Sets.newHashSet(mDownloads.keySet()); final ContentResolver resolver = getContentResolver(); Cursor cursor = null; try { cursor = resolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, null, null, null); final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver, cursor); final int idColumn = cursor.getColumnIndexOrThrow(Downloads.Impl._ID); while (cursor.moveToNext()) { final long id = cursor.getLong(idColumn); long currentDownloadNextActionMillis = Long.MAX_VALUE; DownloadInfo info = mDownloads.get(id); if (info != null) { updateDownload(reader, info, now); } else { // Check xunlei engine status when create a new task info = insertDownloadLocked(reader, now); } if (info.mDeleted) { // Delete download if requested, but only after cleaning up if (!TextUtils.isEmpty(info.mMediaProviderUri)) { resolver.delete(Uri.parse(info.mMediaProviderUri), null, null); } // if download has been completed, delete xxx, else delete xxx.midownload if (info.mStatus == Downloads.Impl.STATUS_SUCCESS) { if (info.mFileName != null) { deleteFileIfExists(info.mFileName); } } else { if (info.mFileName != null) { deleteFileIfExists(info.mFileName + Helpers.sDownloadingExtension); } } resolver.delete(info.getAllDownloadsUri(), null, null); } else { staleIds.remove(id); // Kick off download task if ready String pkg = TextUtils.isEmpty(info.mPackage) ? sUnknownPackage : info.mPackage; final boolean activeDownload = info.startDownloadIfReady(MyExecutor.getExecutorInstance(pkg)); // Kick off media scan if completed final boolean activeScan = info.startScanIfReady(mScanner); // get current download task's next action millis currentDownloadNextActionMillis = info.nextActionMillis(now); XLConfig.LOGD("Download " + info.mId + ": activeDownload=" + activeDownload + ", activeScan=" + activeScan); isActive |= activeDownload; isActive |= activeScan; // if equals 0, keep download service on. isActive |= (currentDownloadNextActionMillis == 0); } // Keep track of nearest next action nextActionMillis = Math.min(currentDownloadNextActionMillis, nextActionMillis); } } catch (SQLiteDiskIOException e) { XLConfig.LOGD("error when updateLocked: ", e); } catch (Exception e) { XLConfig.LOGD("error when updateLocked: ", e); } finally { if (cursor != null) { cursor.close(); } } // Clean up stale downloads that disappeared for (Long id : staleIds) { deleteDownloadLocked(id); } // Update notifications visible to user mNotifier.updateWith(mDownloads.values()); // Set alarm when next action is in future. It's okay if the service // continues to run in meantime, since it will kick off an update pass. if (nextActionMillis > 0 && nextActionMillis < Long.MAX_VALUE) { XLConfig.LOGD("scheduling start in " + nextActionMillis + "ms"); final Intent intent = new Intent(Constants.ACTION_RETRY); intent.setClass(this, DownloadReceiver.class); mAlarmManager.set(AlarmManager.RTC_WAKEUP, now + nextActionMillis, PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } return isActive; }
From source file:ca.ualberta.cs.drivr.MainActivity.java
private void setNotificationAlarm(Context context) { Log.d("ME", "Alarm setup"); Intent intent = new Intent(getApplicationContext(), NotificationReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent);//from w w w .j a v a2s .c om am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, pendingIntent); Log.d("ME", "Alarm started"); }
From source file:se.anyro.tagtider.TransferActivity.java
private void sendSms(String phoneNumber, String message) { registerReceiver(mSmsStatusReceiver, mSmsSentFilter); PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMS_SENT), 0); ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(); sentIntents.add(sentIntent);//from w w w . j ava2s . c o m SmsManager sms = SmsManager.getDefault(); ArrayList<String> smstext = sms.divideMessage(message); mProgressDialog.setMessage("Skickar SMS..."); mProgressDialog.show(); // Using multipart as a work-around for a bug in HTC Tattoo sms.sendMultipartTextMessage(phoneNumber, null, smstext, sentIntents, null); }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Create an intent to be send to Scheduler to update notification and to (re-)schedule the bell. * * @param isRescheduling/*from ww w .j ava 2s . co m*/ * True if the intents is meant for rescheduling instead of updating bell schedule. * @param nowTimeMillis * If not null millis to be given to Scheduler as now (or nextTargetTimeMillis from the perspective of the previous * call) * @param meditationPeriod * Zero: ramp-up, 1-(n-1): intermediate period, n: last period, n+1: beyond end */ private PendingIntent createSchedulerBroadcastIntent(boolean isRescheduling, Long nowTimeMillis, Integer meditationPeriod) { Log.d(TAG, "Creating scheduler intent: isRescheduling=" + isRescheduling + ", nowTimeMillis=" + nowTimeMillis + ", meditationPeriod=" + meditationPeriod); Intent intent = new Intent(context, Scheduler.class); if (isRescheduling) { intent.putExtra(EXTRA_IS_RESCHEDULING, true); } if (nowTimeMillis != null) { intent.putExtra(EXTRA_NOW_TIME_MILLIS, nowTimeMillis); } if (meditationPeriod != null) { intent.putExtra(EXTRA_MEDITATION_PERIOD, meditationPeriod); } return PendingIntent.getBroadcast(context, SCHEDULER_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.notalenthack.blaster.CommandActivity.java
private void cancelStatusUpdate() { // Setup expiration if we never get a message from the service AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(); intent.setAction(Constants.ACTION_REFRESH_STATUS); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi);//from ww w. j ava 2s.co m }
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * Initializes the remote control client *///from w ww .java 2s . c o m private void setUpRemoteControlClient() { final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT)); try { if (mAudioManager != null) { mAudioManager.registerRemoteControlClient(mRemoteControlClient); } } catch (Throwable t) { // seems like this doesn't work on some devices where it requires MODIFY_PHONE_STATE // which is a permission only given to system apps, not third party apps. } // Flags for the media transport control that this client supports. int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; flags |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE; mRemoteControlClient.setOnGetPlaybackPositionListener(this::position); mRemoteControlClient.setPlaybackPositionUpdateListener(this::seek); mRemoteControlClient.setTransportControlFlags(flags); }
From source file:com.geryon.ocraa.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next.// w w w. j av a 2 s . c o m */ void playNextSong(int pos) { position = pos; mState = State.Stopped; progressBarHandler.removeCallbacks(mUpdateTimeTask); MusicRetriever.Item playingItem = null; relaxResources(false); // release everything except MediaPlayer try { if ((position == -1) || (repeat == false && shuffle == true)) { Random mRandom = new Random(); int random = mRandom.nextInt(mRetriever.ItemSize()); playingItem = mRetriever.getItem(random); Log.d("Randomize:", String.valueOf(random)); position = random; Log.d("Position:", String.valueOf(random)); if (playingItem == null) { Toast.makeText(this, "No available music to play. Place some music on your external storage " + "device (e.g. your SD card) and try again.", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } else if (position != -1) { if (repeat == false) { if (shuffle == false) { if (position == mRetriever.ItemSize() - 1) { position = 0; } else { position++; } } } playingItem = mRetriever.getItem(position); createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } mSongTitle = playingItem.getTitle(); mState = State.Preparing; setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, playingItem.getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, playingItem.getAlbum()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, playingItem.getDuration()) // TODO: fetch real item artwork .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); updateProgressBar(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { // Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); // ex.printStackTrace(); } }