PendingIntent getService - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PendingIntent getService method.

This code example shows how to use the following methods:getService, getSystemService
            Toast.makeText(context, context.getString(R.string.start_fetch_msg), Toast.LENGTH_SHORT).show();
        } 
    } 
 
    public static void stopAlarm(Context context, boolean clearNotification) {
        AlarmManager alarm = (AlarmManager) context.getSystemService(
                Context.ALARM_SERVICE);
        Intent intent = new Intent(context, FetchNewMsgService.class);
        PendingIntent sender = PendingIntent.getService(context, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        alarm.cancel(sender);
        if (clearNotification) {
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(Long.valueOf(GlobalContext.getInstance().getCurrentAccountId()).intValue());
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getService, getSystemService, getDefaultSharedPreferences
        } 
	} 
	 
	public static void setAlarm(Context context) {
		PendingIntent alarmSender;
		alarmSender = PendingIntent.getService(context, 0, new Intent(context, AutoRefreshService.class), PendingIntent.FLAG_UPDATE_CURRENT);
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean autoUpdatesEnabled = prefs.getBoolean("autoupdates_enabled", true);
        Integer refreshRate = Integer.parseInt(prefs.getString("refresh_rate", "0")); 
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        if (!autoUpdatesEnabled) {
        	am.cancel(alarmSender);
        } 
        else { 
	        long firstTime = SystemClock.elapsedRealtime();
	        int secondsInMinute = 60;
	        if (prefs.getBoolean("debug_mode", false) && prefs.getBoolean("debug_refreshrate_in_seconds", false)) {
	            secondsInMinute = 1;
	        } 
	        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime+refreshRate*secondsInMinute*1000, refreshRate*secondsInMinute*1000, alarmSender);

7
CodeRank
This code example shows how to use the following methods:getService, getSystemService
    scheduleAlarms(ctxt);
  } 
 
  static void scheduleAlarms(Context ctxt) {
    AlarmManager mgr=
        (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
    Intent i=new Intent(ctxt, ScheduledService.class);
    PendingIntent pi=PendingIntent.getService(ctxt, 0, i, 0);
 
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME,
                     SystemClock.elapsedRealtime() + PERIOD, PERIOD, pi);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:getService, getSystemService
 
    /** 
     * Removes repeating alarm for auto-synchronization 
     */ 
    private void unscheduleService(Context context) {
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        PendingIntent pendingIntent = PendingIntent.getService(context, getSyncUtilities().getSyncIntervalKey(),
                createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
        am.cancel(pendingIntent);
    } 
 
    /** Create the alarm intent */ 
    private Intent createAlarmIntent(Context context) {
        Intent intent = new Intent(context, getClass());
        return intent;
    } 
 
    // --- utility methods 
 
    private long computeNextSyncOffset(long interval) {
7
CodeRank
This code example shows how to use the following methods:getService, getSystemService
    }; 
     
    public static void resetAlarm(Context context, long interval) {
        // Create an IntentSender that will launch our service, to be scheduled 
        // with the alarm manager. 
        PendingIntent alarmSender = PendingIntent.getService(context, 0, new Intent(context, EnvelopeService.class), 0);
        AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
        am.cancel(alarmSender);
        if (interval != 0)
        	am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), interval, alarmSender);
    } 
} 
 
7
CodeRank
This code example shows how to use the following methods:getService
		startService(new Intent(this, PingService.class));
	} 
	 
	public void cancelAlarm() { 
		AlarmManager alarum = (AlarmManager) getSystemService(ALARM_SERVICE);
		alarum.cancel(PendingIntent.getService(this, 0, 
				new Intent(this, PingService.class), 0));		
	} 
	 
	private OnClickListener mTogListener = new OnClickListener() {
		public void onClick(View v) { 
			SharedPreferences.Editor editor = mSettings.edit(); 
 
			// Perform action on clicks 
			if (tog.isChecked()) { 
				Toast.makeText(TPController.this, "Pings ON", Toast.LENGTH_SHORT).show(); 
				mRunning = true; 
				editor.putBoolean(KEY_RUNNING, mRunning); 
				setAlarm(); 
			} else { 
6
CodeRank
This code example shows how to use the following methods:getService
 
	@Override 
	public void onCreate() { 
		Log.i(TAG, "onCreate()");
 
		Intent intent = new Intent(this, ScheduleService.class);
		mScheduleExecutor = PendingIntent.getService(this, 0, intent, 0);
 
		startSchedule(); 
 
	} 
 
	@Override 
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.i(TAG, "onStartCommand() intent:" + intent + " flags:" + flags + " startId:" + startId);
 
		return START_STICKY;
	} 
 
	@Override 
7
CodeRank
This code example shows how to use the following methods:getService, putExtra
 
		mNM.notify(notificationID, notification);
	} 
	 
	private void setUpdateAlarm() { 
		Intent intent = new Intent(this, TimeclockService.class);
		intent.putExtra("action", TIMECLOCK_UPDATE);
		this.updateIntent = PendingIntent.getService(appInst, 1,
				intent, 0);
		alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis()
				+ DateUtils.MINUTE_IN_MILLIS, DateUtils.MINUTE_IN_MILLIS, updateIntent);
	} 
	 
	private void setTimeoutAlarm(int hour, int minute) {
		if(hour <= 0 && minute <= 0)
			return; 
		 
		long time = (hour * DateUtils.HOUR_IN_MILLIS)
				+ (minute * DateUtils.MINUTE_IN_MILLIS);
		 
8
CodeRank
This code example shows how to use the following methods:getService
	private PendingIntent alarm_sender;
 
	@Override 
	public void onCreate() { 
		super.onCreate(); 
		alarm_sender = PendingIntent.getService(AlarmHostService.this, 0, new Intent(AlarmHostService.this, AlarmService.class), 0);
	} 
 
	@Override 
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		 
		SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
 
		AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
 
		//Set the alarm time 
 		String time = app_preferences.getString("timeAutoDownload", "2:0");
 		GregorianCalendar currentCalendar = new GregorianCalendar();
 		long alarmTime = new GregorianCalendar(
6
CodeRank
This code example shows how to use the following methods:getService, putExtra, setAction
 
    // PendingIntents are compared without reference to their extras. Therefore 
    // even though we pass the profile details to the action, different 
    // profiles will share the *same* pending intent. In a multi-profile future, 
    // this will need to be addressed.  See Bug 882182. 
    final Intent service = new Intent(context, serviceClass);
    service.setAction("upload"); // PendingIntents "lose" their extras if no action is set.
    service.putExtra("uploadEnabled", enabled);
    service.putExtra("profileName", profileName);
    service.putExtra("profilePath", profilePath);
    final PendingIntent pending = PendingIntent.getService(context, 0, service, PendingIntent.FLAG_CANCEL_CURRENT);
 
    if (!serviceEnabled) {
      cancelAlarm(pending);
      return; 
    } 
 
    final long pollInterval = getSubmissionPollInterval();
    scheduleAlarm(pollInterval, pending);
  } 
8
CodeRank

Related PendingIntent getService Questions & Answers:

getService Method Overview
Retrieve a PendingIntent that will start a service, like calling Context.startService().
See Code Examples for other Android PendingIntent Methods: