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.atlas.mars.weatherradar.MainActivity.java
void alarmOn() { am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); intent1 = createIntent("action 1", "extra 1", SampleBootReceiver.class); pIntent1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pIntent1);//from w ww. j av a 2 s . co m //todo ?? //am.set(AlarmManager.RTC_WAKEUP, startAlarm, pIntent1); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1 * 1000, pIntent1); }
From source file:by.zatta.pilight.connection.ConnectionService.java
private static void makeNotification(NotificationType type, String message) { Intent main;/*from ww w. ja v a2s. c o m*/ Intent kill; PendingIntent sentBroadcast; PendingIntent startMainActivity; PendingIntent killService; String myDate = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); //Log.v(TAG, "setting notification: " + type.name() + " while current = " + mCurrentNotif.name()); if (type != mCurrentNotif) { //Log.v(TAG, "setting NEW notification: " + type.name()); sendMessageToUI(MSG_SET_STATUS, type.name()); switch (type) { case DESTROYED: builder = new Notification.Builder(ctx); builder.setSmallIcon(R.drawable.eye_black).setLargeIcon(bigPic(R.drawable.eye_black)) .setContentTitle(aCtx.getString(R.string.app_name)).setContentText(message); mCurrentNotif = NotificationType.DESTROYED; break; case CONNECTING: kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message).setDeleteIntent(killService).setSmallIcon(R.drawable.eye_trans) .setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.CONNECTING; break; case CONNECTED: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setContentIntent(startMainActivity) .setSmallIcon(R.drawable.eye_white).setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.CONNECTED; break; case FAILED: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle("pilight") .setContentText(aCtx.getString(R.string.noti_failed)).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.FAILED; break; case LOST_CONNECTION: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.LOST_CONNECTION; break; case UPDATE: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder = new Notification.Builder(ctx).setContentTitle(title[0]).setContentText(message) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(startMainActivity).setSmallIcon(R.drawable.eye_white) .setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.UPDATE; break; default: break; } } else { if (message != null) { if (message.contains("Stamp")) { String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder.setContentTitle(title[0]).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } else { builder.setContentTitle(myDate).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } } } mNotMan.notify(35, builder.build()); }
From source file:com.geotrackin.gpslogger.GpsLoggingService.java
private void CancelAlarm() { tracer.debug("."); if (alarmIntent != null) { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent sender = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); tracer.debug("Pending alarm intent was null? " + String.valueOf(sender == null)); am.cancel(sender);//w w w . ja va2 s . co m } }
From source file:com.atlas.mars.weatherradar.MainActivity.java
void alarmCancel() { if (pIntent1 != null && am != null) { pIntent1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pIntent1);//from ww w . j av a2 s .c o m } }
From source file:com.intel.RtcPingDownloadTester.java
private void setAlarm(long millis) { Intent intent = new Intent(ACTION_NAME); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Log.v(TAG, "setAlarm millis = " + millis); if (millis == 0) return;/*from ww w.ja v a 2 s. c om*/ AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pendingIntent); return; }
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, Notification.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;//from w w w . j a v a2 s. c om } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:com.jefftharris.passwdsafe.NotificationMgr.java
/** Load the expiration entries from the database */ private void loadEntries(SQLiteDatabase db) throws SQLException { long expiration; if (itsExpiryFilter != null) { expiration = itsExpiryFilter.getExpiryFromNow(null); } else {/*from w ww . java 2 s . c o m*/ expiration = Long.MIN_VALUE; } LongReference nextExpiration = new LongReference(Long.MAX_VALUE); itsNotifUris.clear(); HashSet<Long> uris = new HashSet<>(); ArrayList<Long> removeUriIds = new ArrayList<>(); Cursor uriCursor = db.query(DB_TABLE_URIS, new String[] { DB_COL_URIS_ID, DB_COL_URIS_URI }, null, null, null, null, null); try { while (uriCursor.moveToNext()) { long id = uriCursor.getLong(0); Uri uri = Uri.parse(uriCursor.getString(1)); boolean exists = loadUri(id, uri, uris, expiration, nextExpiration, db); if (!exists) { removeUriIds.add(id); } } } finally { uriCursor.close(); } Iterator<HashMap.Entry<Long, UriNotifInfo>> iter = itsUriNotifs.entrySet().iterator(); while (iter.hasNext()) { HashMap.Entry<Long, UriNotifInfo> entry = iter.next(); if (!uris.contains(entry.getKey())) { itsNotifyMgr.cancel(entry.getValue().getNotifId()); iter.remove(); } } for (Long removeId : removeUriIds) { removeUri(removeId, db); } PasswdSafeUtil.dbginfo(TAG, "nextExpiration: %tc", nextExpiration.itsValue); if ((nextExpiration.itsValue != Long.MAX_VALUE) && (itsExpiryFilter != null)) { if (itsTimerIntent == null) { Intent intent = new Intent(PasswdSafeApp.EXPIRATION_TIMEOUT_INTENT); itsTimerIntent = PendingIntent.getBroadcast(itsCtx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); } long nextTimer = System.currentTimeMillis() + (nextExpiration.itsValue - expiration); PasswdSafeUtil.dbginfo(TAG, "nextTimer: %tc", nextTimer); itsAlarmMgr.set(AlarmManager.RTC, nextTimer, itsTimerIntent); } else if (itsTimerIntent != null) { PasswdSafeUtil.dbginfo(TAG, "cancel expiration timer"); itsAlarmMgr.cancel(itsTimerIntent); } }
From source file:com.google.fpl.gim.examplegame.MainService.java
/** * Create a notification action that upon selection triggers the provided action. * @param intent Intent to carry out when the notification action is selected. * @param actionIconResourceId Resource Id of icon for this action. * @param actionDescription Name of this action. * @return A notification action that can be selected. *//*from w w w. j a va 2 s. c o m*/ public NotificationCompat.Action makeNotificationAction(Intent intent, int actionIconResourceId, String actionDescription) { PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Action(actionIconResourceId, actionDescription, pendingIntent); }
From source file:net.kidlogger.kidlogger.KLService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { //List file synchronizer listFileSync = new ListFileSync(this); // Check a previous file and send the file if exist checkPrevFiles();// w w w.ja va2 s.co m // Handle outgoing call delay mHandler = new Handler() { public void handleMessage(Message msg) { String message = (String) msg.obj; if (message == null) return; //Log.i("KLS", "message: " + message); if (message.equals("start")) { delayNewCallEvent = new CountDownTimer(15000L, 1000L) { public void onTick(long millisUntilFinish) { } public void onFinish() { new Thread(new Runnable() { public void run() { //Log.i("KLS", "doAfterDelay"); doAfterDelay(); } }).start(); } }.start(); } else if (message.equals("stop")) { //Log.i("KLS", "Stop delay"); if (delayNewCallEvent != null) { delayNewCallEvent.cancel(); delayNewCallEvent = null; } } } }; // Define a BroadcastReceiver to detect if date is changed /*dateChanged = new BroadcastReceiver(){ public void onReceive(Context context, Intent intent){ String action = intent.getAction(); if(action != null && action.equals(Intent.ACTION_DATE_CHANGED)){ new Thread(new Runnable(){ public void run(){ checkPrevFiles(); app.logError(CN, "Date is changed"); } }).start(); } } }; IntentFilter filter = new IntentFilter(Intent.ACTION_DATE_CHANGED); registerReceiver(dateChanged, filter);*/ // Stub of remote service remoteServiceStub = new IRemoteService.Stub() { public void sendString(String string) throws RemoteException { runKeyEvent(string); } }; // Setup things to log setupLogging(); // Uploading files if (Settings.uploadLogs(this)) { mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (mAlarmManager == null) { app.logError(CN + "onStartCommand", "Couldn't get AlarmManager"); uploadOn = false; } else { //Intent i = new Intent(this, AlarmReceiver.class); Intent i = new Intent(KLService.ALARM_ACTION); mPI = PendingIntent.getBroadcast(this, 0, i, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), postSendingFreq, mPI); } //--------------------------------------------------------------------------------- /*mUploadData = new Runnable(){ public void run(){ new Thread(new Runnable(){ public void run(){ //doSendingFile(); doSendHtml(); checkDate(); if(!mIsRoaming) doSendMedia(); } }).start(); handlering.postDelayed(mUploadData, postSendingFreq); } }; handlering.postDelayed(mUploadData, postSendingFreq);*/ //--------------------------------------------------------------------------------- uploadOn = true; } // Log power boolean powerOn = getBoolPref("powerOff"); if (powerOn) { new Thread(new Runnable() { public void run() { sync.writeLog(".htm", Templates.getPowerLog(false)); } }).start(); //WriteThread wpl = new WriteThread(sync, ".htm", Templates.getPowerLog(false)); saveToPref("powerOff", false); } // Log start service logServiceState(true); app.mService = this; app.mServiceOnCreate = false; //Log.i(CN + "onStartCommand", "onStartCommand"); return START_STICKY; }