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.android.exchange.ExchangeService.java
private void setAlarm(long id, long millis) { synchronized (mPendingIntents) { PendingIntent pi = mPendingIntents.get(id); if (pi == null) { Intent i = new Intent(this, MailboxAlarmReceiver.class); i.putExtra("mailbox", id); i.setData(Uri.parse("Box" + id)); pi = PendingIntent.getBroadcast(this, 0, i, 0); mPendingIntents.put(id, pi); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pi); //log("+Alarm set for " + alarmOwner(id) + ", " + millis/1000 + "s"); }/*from w w w .j av a 2s . co m*/ } }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseCastManager.FEATURE_LOCKSCREEN)) { return;// w ww . java 2 s .co m } LOGD(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:com.xorcode.andtweet.AndTweetService.java
/** * Returns Intent to be send with Repeating Alarm. * This alarm will be received by {@link AndTweetServiceManager} * @return the Intent/*from w w w. j a v a 2 s. c o m*/ */ private PendingIntent getRepeatingIntent() { Intent intent = new Intent(ACTION_ALARM); intent.putExtra(AndTweetService.EXTRA_MSGTYPE, CommandEnum.AUTOMATIC_UPDATE.save()); PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0); return pIntent; }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseChromeCastManager.FEATURE_LOCKSCREEN)) { return;//from w w w .ja v a 2 s.com } Log.d(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SETTINGS_CODE) { // Log.d("Debug", "Notification alarm set"); alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); }// w ww. j av a2 s. c om if (requestCode == OPTION_CODE) { String json = ""; // Get Options getOptions(); /*************************************** * Save qBittorrent's options remotely * ****************************************/ // Maximum global number of simultaneous connections json += "\"max_connec\":" + global_max_num_connections; // Maximum number of simultaneous connections per torrent json += ",\"max_connec_per_torrent\":" + max_num_conn_per_torrent; // Global maximum number of upload slots: json += ",\"max_uploads\":" + max_uploads; // Maximum number of upload slots per torrent json += ",\"max_uploads_per_torrent\":" + max_num_upslots_per_torrent; // Global upload speed limit in KiB/s; -1 means no limit is applied json += ",\"up_limit\":" + global_upload; // Global download speed limit in KiB/s; -1 means no limit is // applied json += ",\"dl_limit\":" + global_download; // alternative global upload speed limit in KiB/s json += ",\"alt_up_limit\":" + alt_upload; // alternative global upload speed limit in KiB/s json += ",\"alt_dl_limit\":" + alt_download; // Is torrent queuing enabled ? json += ",\"queueing_enabled\":" + torrent_queueing; // Maximum number of active simultaneous downloads json += ",\"max_active_downloads\":" + max_act_downloads; // Maximum number of active simultaneous uploads json += ",\"max_active_uploads\":" + max_act_uploads; // Maximum number of active simultaneous downloads and uploads json += ",\"max_active_torrents\":" + max_act_torrents; // Schedule alternative rate limits json += ",\"scheduler_enabled\":" + schedule_alternative_rate_limits; // Scheduler starting hour json += ",\"schedule_from_hour\":" + alt_from_hour; // Scheduler starting min json += ",\"schedule_from_min\":" + alt_from_min; // Scheduler ending hour json += ",\"schedule_to_hour\":" + alt_to_hour; // Scheduler ending min json += ",\"schedule_to_min\":" + alt_to_min; // Scheduler scheduler days json += ",\"scheduler_days\":" + scheduler_days; // Log.d("Debug", "max_ratio_enabled:" + max_ratio_enabled); // Share Ratio Limiting json += ",\"max_ratio_enabled\":" + max_ratio_enabled; if (max_ratio_enabled == false) { json += ",\"max_ratio\":-1"; } else { json += ",\"max_ratio\":" + Float.parseFloat(max_ratio); } // String max_ratio_string = "4) max_ratio: " + Float.parseFloat(max_ratio); // Log.d("Debug", "3) max_ratio: " + Float.parseFloat(max_ratio)); // Log.d("Debug", max_ratio_string ); json += ",\"max_ratio_act\":" + max_ratio_act; // Put everything in an json object json = "{" + json + "}"; // Set preferences using this json object setQBittorrentPrefefrences(json); // Now it can be refreshed canrefresh = true; } if (requestCode == HELP_CODE && resultCode == RESULT_OK) { // Now it can be refreshed canrefresh = true; refreshSwipeLayout(); refreshCurrent(); } if (requestCode == SETTINGS_CODE && resultCode == RESULT_OK) { // Change current server (from settings or drawer menu) changeCurrentServer(); } if (requestCode == ADDFILE_CODE && resultCode == RESULT_OK) { String file_path_value = ""; // MaterialDesignPicker if (requestCode == ADDFILE_CODE && resultCode == RESULT_OK) { file_path_value = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH); } Log.d("Debug", "Torrent path: " + file_path_value); // Do something with the file path addTorrentFile(file_path_value); } }
From source file:knayi.delevadriver.JobDetailActivity.java
private void startAlarmManager() { Log.d("TAG", "startAlarmManager"); Context context = getBaseContext(); alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), intervalInMinutes * 10000, // 60000 = 1 minute pendingIntent);//from ww w . j av a 2 s .c o m //startService(new Intent(JobDetailActivity.this, GPSLocationService.class)); }
From source file:knayi.delevadriver.AvaliableJobDetailActivity.java
private void cancelAlarmManager() { Log.d("TAG", "cancelAlarmManager"); Context context = getBaseContext(); //Intent gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);/*from w ww . j av a 2 s .c om*/ }
From source file:knayi.delevadriver.AvaliableJobDetailActivity.java
private void startAlarmManager() { Log.d("TAG", "startAlarmManager"); Context context = getBaseContext(); alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), intervalInMinutes * 10000, // 60000 = 1 minute pendingIntent);//w w w .j av a 2 s .com //startService(new Intent(AvaliableJobDetailActivity.this, GPSLocationService.class)); }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/*from w w w . j a v a2s. c o m*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("com.goftagram.telegram.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("com.goftagram.telegram.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent) .extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:com.av.remusic.service.MediaService.java
public void timing(int time) { PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(PAUSE_ACTION), PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC, System.currentTimeMillis() + time, pendingIntent); }