Android Open Source - AsteroidGetLocationOverBT Manager Service






From Project

Back to project page AsteroidGetLocationOverBT.

License

The source code is released under:

Apache License

If you think the Android project AsteroidGetLocationOverBT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.freak.fidji.locationoverbt;
/* www .  j  av a 2 s  .  c  o m*/
import android.app.IntentService;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

public class ManagerService extends IntentService {

    private static final boolean DEBUG = true;
    private static final String TAG = "MANAGER_SERVICE";

    private String mState;
    private BluetoothDevice mDevice;

    public ManagerService() {
        super("ManagerService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (DEBUG)
            Log.d(TAG, "Create service, handle intent");
        if (intent != null) {
            mState = intent.getStringExtra(BtEventsReceiver.ACTION_EXTRA);
            mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            Intent serviceIntent = new Intent(this, MyService.class);
            if (DEBUG)
                Log.d(TAG, "Start service");
            this.startService(serviceIntent);
            if (DEBUG)
                Log.d(TAG, "Bind service");
            this.bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
        }
    }

    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            if (DEBUG)
                Log.d(TAG, "Service connected");

            MyService myService = ((MyService.LocalBinder)service).getService();
            if (mState.equals(BluetoothDevice.ACTION_ACL_CONNECTED)){
                if (DEBUG)
                    Log.d(TAG, "Start thread");
                myService.startThread(mDevice);
            }
            else if (mState.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)){
                if (DEBUG)
                    Log.d(TAG, "Stop thread");
                myService.stopThread(mDevice);
            }
            else {
                if (DEBUG)
                    Log.d(TAG, "Unknown action");
            }
            ManagerService.this.unbindService(mConnection);
        }

        public void onServiceDisconnected(ComponentName className) {
            if (DEBUG)
                Log.d(TAG, "Service disconnected");
        }
    };

    @Override
    public void onDestroy() {
        if (DEBUG)
            Log.d(TAG, "Destroy service");
        super.onDestroy();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (DEBUG)
            Log.d(TAG, "Create service");
    }
}




Java Source Code List

com.freak.android.getlocation.ApplicationTest.java
com.freak.android.getlocation.MyActivity.java
com.freak.android.getlocation.MyReceiver.java
com.freak.android.getlocation.MyService.java
com.freak.android.getlocation.ReceiveThreadListener.java
com.freak.android.getlocation.ReceiveThread.java
com.freak.android.getlocation.StatisticsActivity.java
com.freak.fidji.locationoverbt.ApplicationTest.java
com.freak.fidji.locationoverbt.BtEventsReceiver.java
com.freak.fidji.locationoverbt.ManagerService.java
com.freak.fidji.locationoverbt.MyService.java
com.freak.fidji.locationoverbt.SendingThreadListener.java
com.freak.fidji.locationoverbt.SendingThread.java