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:Main.java
public static final void openGPS(Context context) { try {//from ww w.j av a 2 s . c o m if (!isOpenGPS(context)) { Intent GPSIntent = new Intent(); GPSIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); GPSIntent.addCategory("android.intent.category.ALTERNATIVE"); GPSIntent.setData(Uri.parse("custom:3")); PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, Long alertTime, String titleText, String subtitleText, String messageBodyText, String tickerText) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); }/* w w w . j ava2s . c o m*/ return pendingIntent; }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message, Long alertTime, int repeat) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { if (repeat == 0) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); } else {/*from w w w .j a v a 2s . c o m*/ Calendar alarmStartTime = Calendar.getInstance(); alarmStartTime.add(Calendar.MINUTE, 1); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent); } } return pendingIntent; }
From source file:Main.java
public static synchronized boolean isBroadcastAlarmOn(Context context, Intent intent, int identifier) { PendingIntent pi = PendingIntent.getBroadcast(context, identifier, intent, PendingIntent.FLAG_NO_CREATE); return pi != null; }
From source file:Main.java
public static void openGPS(Context context) { Log.d(TAG, "openGPS"); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Intent gpsIntent = new Intent(); gpsIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); gpsIntent.addCategory("android.intent.category.ALTERNATIVE"); gpsIntent.setData(Uri.parse("custom:3")); try {//from w ww .j av a 2 s . c om PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send(); } catch (CanceledException e) { Log.d(TAG, "openGPS exception:" + e.getMessage()); e.printStackTrace(); } } }
From source file:Main.java
private static IntentSender createIntentSender(Context context, int sessionId) { PendingIntent pendingIntent = PendingIntent.getBroadcast(context, sessionId, new Intent(ACTION_INSTALL_COMPLETE), 0); return pendingIntent.getIntentSender(); }
From source file:Main.java
public static synchronized long setBroadcastAlarm(Context context, Intent intent, long timeInterval, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getBroadcast(context, identifier, intent, PendingIntent.FLAG_CANCEL_CURRENT); return setUpAlarm(am, pi, timeInterval); }
From source file:Main.java
public static void sendSMS(Context context, String number, String content) { SmsManager smsManager = SmsManager.getDefault(); PendingIntent sendIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0); smsManager.sendTextMessage(number, null, content, sendIntent, null); }
From source file:Main.java
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, clazz); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Random random = new Random(System.currentTimeMillis()); long offset = random.nextLong() % (12 * 60 * 60 * 1000); long interval = (24 * 60 * 60 * 1000) + offset; String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName(); long scheduledTime = preferences.getLong(prefKey, -1); if (scheduledTime == -1) { context.sendBroadcast(intent);// ww w . j a va 2 s. com } if (scheduledTime <= System.currentTimeMillis()) { context.sendBroadcast(intent); scheduledTime = System.currentTimeMillis() + interval; preferences.edit().putLong(prefKey, scheduledTime).commit(); Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } else { Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } am.cancel(sender); am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); }
From source file:com.commonsware.android.wakecast.PollReceiver.java
static void scheduleAlarms(Context ctxt) { AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(ctxt, PollReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY, PERIOD, pi);// w ww.j a va 2 s . c om }