Example usage for android.content ServiceConnection ServiceConnection

List of usage examples for android.content ServiceConnection ServiceConnection

Introduction

In this page you can find the example usage for android.content ServiceConnection ServiceConnection.

Prototype

ServiceConnection

Source Link

Usage

From source file:org.ohmage.reminders.types.location.LocTrigService.java

private void startMotionDetection() {
    Log.v(TAG, "LocTrigService: Starting motion detection...");

    mWifiGPSServConn = new ServiceConnection() {
        @Override//ww w  .ja  va2  s .  co  m
        public void onServiceDisconnected(ComponentName name) {
            Log.v(TAG, "LocTrigService: WifiGPS disconnected");

            mWiFiGPSServ = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.v(TAG, "LocTrigService: WifiGPS connected");

            mWiFiGPSServ = IWiFiGPSLocationService.Stub.asInterface(service);
            registerMotionDetectionCB();
        }
    };

    mAccelServConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.v(TAG, "LocTrigService: AccelService disconnected");

            mAccelServ = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.v(TAG, "LocTrigService: AccelService connected");

            mAccelServ = IAccelService.Stub.asInterface(service);
            registerMotionDetectionCB();
        }
    };

    connectToRemoteServices();
}

From source file:org.ohmage.triggers.types.location.LocTrigService.java

private void startMotionDetection() {
    Log.i(DEBUG_TAG, "LocTrigService: Starting motion detection...");

    mWifiGPSServConn = new ServiceConnection() {
        @Override/*  w  w w .  ja  va  2s  .c  om*/
        public void onServiceDisconnected(ComponentName name) {
            Log.i(DEBUG_TAG, "LocTrigService: WifiGPS disconnected");

            mWiFiGPSServ = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.i(DEBUG_TAG, "LocTrigService: WifiGPS connected");

            mWiFiGPSServ = IWiFiGPSLocationService.Stub.asInterface(service);
            registerMotionDetectionCB();
        }
    };

    mAccelServConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.i(DEBUG_TAG, "LocTrigService: AccelService disconnected");

            mAccelServ = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.i(DEBUG_TAG, "LocTrigService: AccelService connected");

            mAccelServ = IAccelService.Stub.asInterface(service);
            registerMotionDetectionCB();
        }
    };

    connectToRemoteServices();
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

private void checkNiLSPlusLicense() {
    // if so - request a license
    Intent licenseService = new Intent();
    licenseService.setComponent(/* w  w w .j a v a  2s  .  c o m*/
            new ComponentName("com.roymam.android.nilsplus", "com.roymam.android.nilsplus.LicenseService"));
    mLicenseServiceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            mService = new Messenger(service);
            try {
                // request a license from NiLSPlus app
                Message msg = Message.obtain(null, MSG_REQUEST_LICENSE);
                msg.replyTo = mMessenger;
                mService.send(msg);
            } catch (RemoteException e) {
            }
        }

        public void onServiceDisconnected(ComponentName className) {
            mService = null;
        }
    };
    try {
        bindService(licenseService, mLicenseServiceConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception exp) {
        Log.d("NiLS", "cannot communicate with NiLS Unlocker");
        exp.printStackTrace();
    }
}

From source file:com.andreadec.musicplayer.MainActivity.java

private void createMusicConnection() {
    musicConnection = new ServiceConnection() {
        @Override//from   w  ww . java 2s . c  om
        public void onServiceConnected(ComponentName className, IBinder service) {
            musicService = ((MusicService.MusicBinder) service).getService();
            startRoutine();
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            musicService = null;
        }
    };
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onStart() {
    super.onStart();
    FirstFrameAnimatorHelper.setIsVisible(true);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onStart();/*  w  w  w.jav a2 s  . c  o m*/
    }

    if (AppSettings.getInstance(this).shouldPersist) {
        Intent persister = new Intent(getApplicationContext(), PersisterService.class);
        bindService(persister, new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                Log.v("blur_persister", "connection to persistent service established");
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                Log.v("blur_persister", "connection to persistent service destroyed");
            }
        }, Context.BIND_AUTO_CREATE);
    }
}

From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java

final private void bindSchedulerService(final NotifyEvent p_ntfy) {
    if (mSvcServer != null)
        return;//from  ww w. j av a  2  s . c  o m
    mGlblParms.util.addDebugMsg(1, "I", "bindScheduler entered");

    mSvcConnScheduler = new ServiceConnection() {
        final public void onServiceConnected(ComponentName name, IBinder service) {
            mGlblParms.util.addDebugMsg(1, "I", "Callback onServiceConnected entered");
            mSvcServer = ISchedulerClient.Stub.asInterface(service);
            setCallbackListener();
            if (p_ntfy != null)
                p_ntfy.notifyToListener(true, null);
        }

        final public void onServiceDisconnected(ComponentName name) {
            mGlblParms.util.addDebugMsg(1, "I", "Callback onServiceDisconnected entered");
            mSvcServer = null;
        }
    };
    Intent intent = new Intent(mContext, SchedulerService.class);
    intent.setAction("Main");
    bindService(intent, mSvcConnScheduler, BIND_AUTO_CREATE);
}

From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java

private void openService(final NotifyEvent p_ntfy) {
    util.addDebugLogMsg(1, "I", "openService entered");
    mSvcConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName arg0, IBinder service) {
            util.addDebugLogMsg(1, "I", "onServiceConnected entered");
            mSvcClient = ISvcClient.Stub.asInterface(service);
            p_ntfy.notifyToListener(true, null);
        }//from   www .j a v a 2 s.  com

        public void onServiceDisconnected(ComponentName name) {
            mSvcConnection = null;
            util.addDebugLogMsg(1, "I", "onServiceDisconnected entered");
            mSvcClient = null;
            synchronized (tcService) {
                tcService.notify();
            }
        }
    };

    Intent intmsg = new Intent(mContext, SMBSyncService.class);
    intmsg.setAction("MessageConnection");
    bindService(intmsg, mSvcConnection, BIND_AUTO_CREATE);
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Media createBackgroundMedia(final String uri) throws IOException {
    int mediaId = nextMediaId++;
    backgroundMediaCount++;/*from  w  ww.ja  v  a2 s .co  m*/

    Intent serviceIntent = new Intent(getContext(), AudioService.class);
    serviceIntent.putExtra("mediaLink", uri);
    serviceIntent.putExtra("mediaId", mediaId);
    if (background == null) {
        ServiceConnection mConnection = new ServiceConnection() {

            public void onServiceDisconnected(ComponentName name) {

                background = null;
                backgroundMediaServiceConnection = null;
            }

            public void onServiceConnected(ComponentName name, IBinder service) {
                AudioService.LocalBinder mLocalBinder = (AudioService.LocalBinder) service;
                AudioService svc = (AudioService) mLocalBinder.getService();
                background = svc;
            }
        };
        backgroundMediaServiceConnection = mConnection;
        boolean boundSuccess = getContext().bindService(serviceIntent, mConnection,
                getContext().BIND_AUTO_CREATE);
        if (!boundSuccess) {
            throw new RuntimeException("Failed to bind background media service for uri " + uri);
        }
        getContext().startService(serviceIntent);
        while (background == null) {
            Display.getInstance().invokeAndBlock(new Runnable() {
                @Override
                public void run() {
                    Util.sleep(200);
                }
            });
        }
    } else {
        getContext().startService(serviceIntent);
    }

    while (background.getMedia(mediaId) == null) {
        Display.getInstance().invokeAndBlock(new Runnable() {
            public void run() {
                Util.sleep(200);
            }

        });
    }
    Media ret = new MediaProxy(background.getMedia(mediaId)) {

        @Override
        public void play() {
            super.play();
        }

        @Override
        public void cleanup() {
            super.cleanup();
            if (--backgroundMediaCount <= 0) {
                if (backgroundMediaServiceConnection != null) {
                    getContext().unbindService(backgroundMediaServiceConnection);
                }
            }
        }
    };

    return ret;

}

From source file:com.sentaroh.android.SMBSync2.ActivityMain.java

private void openService(final NotifyEvent p_ntfy) {
    util.addDebugMsg(1, "I", "openService entered");
    mSvcConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName arg0, IBinder service) {
            util.addDebugMsg(1, "I", "onServiceConnected entered");
            mSvcClient = ISvcClient.Stub.asInterface(service);
            p_ntfy.notifyToListener(true, null);
        }/*ww  w. j  av  a2 s .  c  o  m*/

        public void onServiceDisconnected(ComponentName name) {
            mSvcConnection = null;
            util.addDebugMsg(1, "I", "onServiceDisconnected entered");
            //              mSvcClient=null;
            //              synchronized(tcService) {
            //                  tcService.notify();
            //              }
        }
    };

    Intent intmsg = new Intent(mContext, SyncService.class);
    intmsg.setAction("Bind");
    bindService(intmsg, mSvcConnection, BIND_AUTO_CREATE);
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void connectToLicensing() {
      mServiceConnL = new ServiceConnection() {
          public void onServiceConnected(ComponentName paramAnonymousComponentName,
                  IBinder paramAnonymousIBinder) {
              System.out.println("Licensing service try to connect.");
              if (listAppsFragment.this.mServiceL == null) {
                  listAppsFragment.this.mServiceL = ILicensingService.Stub.asInterface(paramAnonymousIBinder);
              }//  ww w.  j a v a 2 s.c om
              try {
                  listAppsFragment.this.mServiceL.checkLicense(new Random().nextLong(),
                          listAppsFragment.getInstance().getPackageName(), new ILicenseResultListener.Stub() {
                              public void verifyLicense(int paramAnonymous2Int, String paramAnonymous2String1,
                                      String paramAnonymous2String2) throws RemoteException {
                                  System.out.println(paramAnonymous2Int);
                                  listAppsFragment.this.responseCode = paramAnonymous2Int;
                                  listAppsFragment.removeDialogLP(11);
                                  switch (paramAnonymous2Int) {
                                  case 1:
                                  case 2:
                                  default:
                                      listAppsFragment.handler.post(new Runnable() {
                                          public void run() {
                                              listAppsFragment.this.showMessage(Utils.getText(2131165549),
                                                      Utils.getText(2131165547));
                                          }
                                      });
                                  }
                                  for (;;) {
                                      System.out.println("" + paramAnonymous2String1);
                                      System.out.println(paramAnonymous2String2);
                                      listAppsFragment.this.cleanupService();
                                      return;
                                      listAppsFragment.handler.post(new Runnable() {
                                          public void run() {
                                              listAppsFragment.this.showMessage(Utils.getText(2131165549),
                                                      Utils.getText(2131165548));
                                          }
                                      });
                                      continue;
                                      if ((paramAnonymous2String1 != null) && (paramAnonymous2String2 != null)
                                              && (Utils.checkCoreJarPatch11()) && (Utils.checkCoreJarPatch12())) {
                                          listAppsFragment.handler.post(new Runnable() {
                                              public void run() {
                                                  listAppsFragment.this.showMessage(Utils.getText(2131165549),
                                                          Utils.getText(2131165550));
                                              }
                                          });
                                      } else {
                                          listAppsFragment.handler.post(new Runnable() {
                                              public void run() {
                                                  listAppsFragment.this.showMessage(Utils.getText(2131165549),
                                                          Utils.getText(2131165547));
                                              }
                                          });
                                      }
                                  }
                              }
                          });
                  return;
              } catch (RemoteException paramAnonymousComponentName) {
                  paramAnonymousComponentName.printStackTrace();
              }
          }

          public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {
              System.out.println("Licensing service disconnected.");
              listAppsFragment.this.mServiceL = null;
              listAppsFragment.removeDialogLP(11);
          }
      };
      if (this.mServiceL == null) {
          boolean bool1;
          label311: do {
              try {
                  Intent localIntent = new Intent(new String(
                          Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));
                  localIntent.setPackage("com.android.vending");
                  localIntent.putExtra("xexe", "lp");
                  boolean bool4 = false;
                  bool1 = false;
                  boolean bool3 = false;
                  boolean bool2 = bool4;
                  try {
                      if (getPkgMng().queryIntentServices(localIntent, 0).isEmpty()) {
                          continue;
                      }
                      bool2 = bool4;
                      Iterator localIterator = getPkgMng().queryIntentServices(localIntent, 0).iterator();
                      bool1 = bool3;
                      Object localObject;
                      cleanupService();
                  } catch (Exception localException1) {
                      try {
                          for (;;) {
                              if (!localIterator.hasNext()) {
                                  break label311;
                              }
                              localObject = (ResolveInfo) localIterator.next();
                              if ((((ResolveInfo) localObject).serviceInfo.packageName == null)
                                      || (!((ResolveInfo) localObject).serviceInfo.packageName
                                              .equals("com.android.vending"))) {
                                  break;
                              }
                              localObject = new ComponentName(((ResolveInfo) localObject).serviceInfo.packageName,
                                      ((ResolveInfo) localObject).serviceInfo.name);
                              localIntent = new Intent();
                              bool2 = bool1;
                              localIntent.setComponent((ComponentName) localObject);
                              bool2 = bool1;
                              localIntent.putExtra("xexe", "lp");
                              bool2 = bool1;
                              handler.post(new Runnable() {
                                  public void run() {
                                      listAppsFragment.removeDialogLP(11);
                                      listAppsFragment.showDialogLP(11);
                                      listAppsFragment.progress2.setCancelable(true);
                                      listAppsFragment.progress2.setMessage(Utils.getText(2131165747));
                                  }
                              });
                              bool2 = bool1;
                              bool1 = getInstance().bindService(localIntent, mServiceConnL, 1);
                          }
                      } catch (Exception localException2) {
                          for (;;) {
                          }
                      }
                      localException1 = localException1;
                      bool1 = bool2;
                      localException1.printStackTrace();
                      removeDialogLP(11);
                  }
                  removeDialogLP(11);
                  return;
              } catch (SecurityException localSecurityException) {
                  localSecurityException.printStackTrace();
                  cleanupService();
                  return;
              } catch (Base64DecoderException localBase64DecoderException) {
                  localBase64DecoderException.printStackTrace();
                  cleanupService();
                  return;
              }
          } while (!bool1);
      }
  }