Context bindService - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:bindService, getContentResolver, getPackageManager, getSharedPreferences
 
	private final SharedPreferences mPreferences; //Preferences to store the OpenUDID
	private final Random mRandom;
	 
	private OpenUDID_manager(Context context) {
		mPreferences =  context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
		mContext = context;
		mRandom = new Random();
		mReceivedOpenUDIDs = new HashMap<String, Integer>();
	} 
	 
	@Override 
  	public void onServiceConnected(ComponentName className, IBinder service) {
		//Get the OpenUDID from the remote service 
		try { 
			//Send a random number to the service 
			android.os.Parcel data = android.os.Parcel.obtain(); 
			data.writeInt(mRandom.nextInt());
			android.os.Parcel reply = android.os.Parcel.obtain(); 
			service.transact(1, android.os.Parcel.obtain(), reply, 0);

7
CodeRank
This code example shows how to use the following methods:bindService
		mContext = context;
		mServiceClass = serviceClass;
		mInterfaceClass = interfaceClass;
		mOnServiceReady = onServiceReady;
		Intent serviceIntent = new Intent(context, mServiceClass);
		context.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
	} 
	 
	public void unBind(){ 
		mContext.unbindService(mServiceConnection);
	} 
	 
	public T getServiceInterface() { 
		return mServiceInterface;
	} 
	 
	private ServiceConnection mServiceConnection = new ServiceConnection() {
 
		@Override 
		public void onServiceConnected(ComponentName name, IBinder service) { 
6
CodeRank
This code example shows how to use the following methods:onServiceConnected
 
		@Override 
		public void onServiceConnected(final ComponentName className, final android.os.IBinder service) {
 
			if (mCallback != null) {
				mCallback.onServiceConnected(className, service);
			} 
		} 
 
		@Override 
		public void onServiceDisconnected(final ComponentName className) {
 
			if (mCallback != null) {
				mCallback.onServiceDisconnected(className);
			} 
		} 
	} 
} 
6
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
        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

Related Context bindService Questions & Answers:

bindService Method Overview
Connect to an application service, creating it if needed.
See Code Examples for other Android Context Methods: