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
This code example shows how to use the following methods:getService
 
			int interval = Integer.parseInt(
					this.appSettings.getString("autoSyncInterval", "1800000"),
					10); 
 
			this.alarmIntent = PendingIntent.getService(appInst, 0, new Intent(
					this, SyncService.class), 0);
			alarmManager.setRepeating(AlarmManager.RTC,
					System.currentTimeMillis() + interval, interval,
					alarmIntent);
 
			this.alarmScheduled = true;
		} 
	} 
 
	private void unsetAlarm() { 
		if (this.alarmScheduled) {
			this.alarmManager.cancel(this.alarmIntent);
			this.alarmScheduled = false;
		} 
7
CodeRank
This code example shows how to use the following methods:getService, putExtra
                bigTextStyle.bigText(content);
                bigTextStyle.setSummaryText(account.getUsernick());
                builder.setStyle(bigTextStyle);
 
 
                Intent intent = new Intent(SendReplyToCommentService.this, SendReplyToCommentService.class);
                intent.putExtra("oriMsg", oriMsg);
                intent.putExtra("content", content);
                intent.putExtra("token", token);
                intent.putExtra("account", account);
                intent.putExtra("repostContent", repostContent);
 
 
                intent.putExtra("lastNotificationId", tasksNotifications.get(task));
 
                PendingIntent retrySendIntent = PendingIntent.getService(SendReplyToCommentService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                builder.addAction(R.drawable.send_light, getString(R.string.retry_send), retrySendIntent);
                notification = builder.build();
 
            } else { 
                notification = builder.getNotification();
8
CodeRank
This code example shows how to use the following methods:getService, setAction
 
        Intent intent = new Intent(this, getClass());
        intent.setAction(ACTION_HANDLE_PANIC);
        mPanicHandleIntent = PendingIntent.getService(this, 0, intent, 0);
 
        intent = new Intent(this, getClass());
        intent.setAction(ACTION_TIMER_UPDATE);
        mTimerUpdateIntent = PendingIntent.getService(this, 1, intent, 0);
 
        mNotifyIntent = new Intent(this, BpPanicNotifyActivity.class);
        mNotifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } 
 
    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = intent.getAction();
 
        if (TextUtils.equals(action, ACTION_HANDLE_PANIC)) {
            Log.d(TAG, "Got BP panic intent");
            if (mNotification == null) {
7
CodeRank
This code example shows how to use the following methods:getService, setAction
This code example shows how to use the following methods:getService
 
	@Override 
	public void onReceive(Context arg0, Intent arg1) {
		Log.i("AAA", "Starter Started");
		AlarmManager alarm = (AlarmManager) arg0.getSystemService(Context.ALARM_SERVICE);
		Intent intent = new Intent(arg0, InternetPoller.class);
		PendingIntent pending = PendingIntent.getService(arg0, 0, intent, 0);
		Calendar time = Calendar.getInstance();
		time.set(Calendar.MINUTE, 0);
		time.set(Calendar.SECOND, 0);
		time.set(Calendar.MILLISECOND, 0);
		alarm.setRepeating(AlarmManager.RTC, time.getTime().getTime(), 30 * 1000, pending);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getService
        // If no PendingIntent exists 
        } else { 
 
            // Create an Intent pointing to the IntentService 
        	// TODO correct service? 
            Intent intent = new Intent(mActivity, ReceiveTransitionsIntentService.class);
            /* 
             * Return a PendingIntent to start the IntentService. 
             * Always create a PendingIntent sent to Location Services 
             * with FLAG_UPDATE_CURRENT, so that sending the PendingIntent 
             * again updates the original. Otherwise, Location Services 
             * can't match the PendingIntent to requests made with it. 
             */ 
            return PendingIntent.getService(
                    mActivity,
                    0, 
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:getService, setAction
            } 
        } 
    } 
 
    public static PendingIntent getRefreshIntent(Context context) {
        Intent i = new Intent(context, ClockWidgetService.class);
        i.setAction(ClockWidgetService.ACTION_REFRESH_CALENDAR);
        return PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    } 
 
    public static void cancelUpdates(Context context) {
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        am.cancel(getRefreshIntent(context));
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getService
    notificationManager.notify(0, notification);
  } 
 
  private void createAlarmForNextUpdate() { 
    DateTime plusHours = new DateTime().plusHours(24);
    Intent ultimateIntent = new Intent(this, VersionCheckerService.class);
    PendingIntent intent = PendingIntent.getService(getApplicationContext(), 0, ultimateIntent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, plusHours.getMillis(), intent);
    Log.i(RESULTS_SERVICE_TAG, "Created alarm for VersionCheckerService. Time: "
        + plusHours.toString());
 
  } 
 
} 
6
CodeRank
This code example shows how to use the following methods:disconnect, removeActivityUpdates
	 
	@Override 
	protected void onDestroy() { 
		super.onDestroy(); 
		if(arclient!=null){
			arclient.removeActivityUpdates(pIntent);
			arclient.disconnect();
		} 
		unregisterReceiver(receiver);
	} 
	 
	@Override 
	public void onConnectionFailed(ConnectionResult arg0) {
		Toast.makeText(this, "Connection Failed", Toast.LENGTH_SHORT).show();
	} 
	@Override 
	public void onConnected(Bundle arg0) {
		Intent intent = new Intent(this, ActivityRecognitionService.class);
		pIntent = PendingIntent.getService(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
		arclient.requestActivityUpdates(1000, pIntent);   
5
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, removeActivityUpdates
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            mClient.connect();
        } else { 
            if (mClient == null || !mClient.isConnected()) {
                return; 
            } 
 
            mClient.removeActivityUpdates(mPendingIntent);
            mClient.disconnect();
        } 
 
        PreferenceManager.getDefaultSharedPreferences(this).edit()
                .putBoolean("service", isChecked).commit();
    } 
 
    @Override 
    protected void onDestroy() { 
        super.onDestroy(); 
5
CodeRank
This code example shows how to use the following methods:requestActivityUpdates
    @Override 
    public void onConnected(Bundle bundle) {
        Intent intent = new Intent(this, ActivityRecIntentService.class);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        activityRecognitionClient.requestActivityUpdates(FIVE_MINUTES, pendingIntent);
    } 
 
    @Override 
    public void onDisconnected() { 
    } 
 
    @Override 
    public void onConnectionFailed(ConnectionResult connectionResult) {
    } 
 
    @Override 
    protected void onDestroy() { 
        super.onDestroy(); 
        activityRecognitionClient.disconnect();
4
CodeRank
This code example shows how to use the following methods:requestActivityUpdates
	@Override 
	public void onConnected(Bundle connectionHint) {
		Intent intent = new Intent(context, ActivityRecognitionService.class);
		callbackIntent = PendingIntent.getService(context, 0, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		mActivityRecognitionClient.requestActivityUpdates(latencyInSec * 1000, callbackIntent); 
	} 
 
	@Override 
	public void onDisconnected() { 
	} 
 
} 
4
CodeRank
This code example shows how to use the following methods:
		 * without causing memory leaks by constantly creating new clients. 
		 */ 
		if (mActivityRecognitionClient == null) {
			// Create a new one 
			setActivityRecognitionClient(new ActivityRecognitionClient(
					mContext, this, this));
		} 
		return mActivityRecognitionClient;
	} 
 
	/** 
	 * Get a activity recognition client and disconnect from Location Services 
	 */ 
	private void requestDisconnection() { 
 
		// Disconnect the client 
		getActivityRecognitionClient().disconnect();
 
		// Set the client to null 
		setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
		 * the existing one. This allows multiple attempts to send a request 
		 * without causing memory leaks by constantly creating new clients. 
		 */ 
		if (mActivityRecognitionClient == null) {
			// Create a new one 
			setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
		} 
		return mActivityRecognitionClient;
	} 
 
	/** 
	 * Get a activity recognition client and disconnect from Location Services 
	 */ 
	private void requestDisconnection() { 
 
		// Disconnect the client 
		getActivityRecognitionClient().disconnect();
 
		// Set the client to null 
		setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
CodeRank
This code example shows how to use the following methods:
         * new clients. 
         * 
         */ 
        if (mActivityRecognitionClient == null) {
            // Create a new one 
            setActivityRecognitionClient(new ActivityRecognitionClient(mContext, this, this));
        } 
        return mActivityRecognitionClient;
    } 
 
    /** 
     * Get a activity recognition client and disconnect from Location Services 
     */ 
    private void requestDisconnection() { 
 
        // Disconnect the client 
        getActivityRecognitionClient().disconnect();
 
        // Set the client to null 
        setActivityRecognitionClient(null); 
4
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: