Android Service - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Service class.

This code example shows how to use the following methods:getSystemService, getClass
This code example shows how to use the following methods:getSystemService, getClass
        mSetForegroundArgs[0] = Boolean.FALSE;
        invokeMethod(mSetForeground, mSetForegroundArgs);
    } 
 
    public void init() { 
        mNM = (NotificationManager) mService.getSystemService(Service.NOTIFICATION_SERVICE);
        try { 
            mStartForeground = mService.getClass().getMethod("startForeground",
                    mStartForegroundSignature);
            mStopForeground = mService.getClass().getMethod("stopForeground",
                    mStopForegroundSignature);
            return; 
        } catch (NoSuchMethodException e) {
            // Running on an older platform. 
            mStartForeground = mStopForeground = null;
        } 
        try { 
            mSetForeground = mService.getClass()
                    .getMethod("setForeground", mSetForegroundSignature);
        } catch (NoSuchMethodException e) {

7
CodeRank
This code example shows how to use the following methods:getSystemService, getClass
This code example shows how to use the following methods:stopForeground
class StopForegroundWrapper 
{ 
	public void stopForegroundAndRemoveNotificationIcon(Service service)
	{ 
		// The true argument removes the notification icon. 
		service.stopForeground(true);
	} 
} 
 
6
CodeRank
This code example shows how to use the following methods:setForeground
			private static final PreEclair sInstance = new PreEclair();
		} 
 
		@Override 
		public void showRunningNotification(Service context) {
			context.setForeground(true);
			getNotificationManager(context).notify(ONLINE_NOTIFICATION, newRunningNotification(context));
		} 
 
		@Override 
		public void hideRunningNotification(Service context) {
			context.setForeground(false);
			getNotificationManager(context).cancel(ONLINE_NOTIFICATION);
		} 
	} 
 
	private static class EclairAndBeyond extends ConnectionNotifier { 
		private static class Holder { 
			private static final EclairAndBeyond sInstance = new EclairAndBeyond();
		} 
5
CodeRank
This code example shows how to use the following methods:startForeground
	public void hideActivityNotification(Service context) {
		getNotificationManager(context).cancel(ACTIVITY_NOTIFICATION);
	} 
 
	public void showRunningNotification(Service context) {
		context.startForeground(ONLINE_NOTIFICATION, newRunningNotification(context));
	} 
 
	public void hideRunningNotification(Service context) {
		context.stopForeground(true);
	} 
} 
5
CodeRank
This code example shows how to use the following methods:startForeground
			private static final EclairAndBeyond sInstance = new EclairAndBeyond();
		} 
 
		@Override 
		public void showRunningNotification(Service context) {
			context.startForeground(ONLINE_NOTIFICATION, newRunningNotification(context));
		} 
 
		@Override 
		public void hideRunningNotification(Service context) {
			context.stopForeground(true);
		} 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getSystemService
	 * init 
	 * @param service 
	 */ 
	public static void init(Service service){
		mService = service;
	   	mLocationManager = (LocationManager)service.getSystemService(Context.LOCATION_SERVICE);
	   	loadWazeConfig(); 
	} 
	 
	/************************************************************************************************* 
	 * loadWazeConfig 
	 *  
	 */ 
	public static void loadWazeConfig(){ 
		WazeAppWidgetLog.d("loadWazeConfig" ); 
    	WazePreferences.load(); 
    	WazeUserPreferences.load(); 
    	WazeHistory.load(); 
    	WazeLang.load(WazeUserPreferences.getProperty("System.Language")); 
	} 
5
CodeRank
This code example shows how to use the following methods:getSystemService, getClass
This code example shows how to use the following methods:getSystemService, getClass, setForeground
  public static void setForeground(Service service, Integer notificationId,
      Notification notification) {
    final Class<?>[] startForegroundSignature = new Class[] { int.class, Notification.class };
    Method startForeground = null;
    try { 
      startForeground = service.getClass().getMethod("startForeground", startForegroundSignature);
 
      try { 
        startForeground.invoke(service, new Object[] { notificationId, notification });
      } catch (IllegalArgumentException e) {
        // Should not happen! 
        Log.e("Could not set TriggerService to foreground mode.", e);
      } catch (IllegalAccessException e) {
        // Should not happen! 
        Log.e("Could not set TriggerService to foreground mode.", e);
      } catch (InvocationTargetException e) {
        // Should not happen! 
        Log.e("Could not set TriggerService to foreground mode.", e);
      } 
 

5
CodeRank

Related Android Service Questions & Answers:

Other Android Service Examples

13:	import android.util.Log;
14:	
15:	public class GPSTracker extends Service implements LocationListener {
16:	
17:		private final Context mContext;

Read More

13:	import android.util.Log;
14:	
15:	public class GPSTracker extends Service implements LocationListener {
16:	
17:		private final Context mContext;

Read More

See Code Examples for Android Service Methods: