Android Open Source - p1keyboard Bluez Foreground Service






From Project

Back to project page p1keyboard.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project p1keyboard 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 mobi.omegacentauri.p1keyboard;
//from w  ww.j a v  a 2  s . c  o m
import mobi.omegacentauri.p1keyboard.R;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class BluezForegroundService extends Service {

  private static final String LOG_NAME = "BluezIME:FG";
  
  static final String ACTION_START = "mobi.omegacentauri.p1keyboard.START_FG_SERVICE";
  static final String ACTION_STOP = "mobi.omegacentauri.p1keyboard.STOP_FG_SERVICE";
  private static final int NOTIFICATION_ID = 10; 
  private NotificationManager m_notificationManager;
  private int m_connectionCount = 0;
  
  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
      Log.e(LOG_NAME, "Intent was null");
    } else {
      String action = intent.getAction();
      if (action == null) {
        Log.e(LOG_NAME, "Action was null");
      } else {
        if (ACTION_START.equals(action)) {
            if (m_connectionCount == 0)
              showNotification();
            m_connectionCount++;
          return START_STICKY;
        } else if (ACTION_STOP.equals(action)) {
          m_connectionCount--;
          if (m_connectionCount <= 0)
            stopSelf();
        } else {
          Log.e(LOG_NAME, "Unknown action: " + action);
        }
        
      }
    }
      return START_NOT_STICKY;
  }
  
  private void showNotification() {
    m_notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    PendingIntent settingsIntent = PendingIntent.getActivity(this, 0, new Intent(this, BluezIMESettings.class), 0);

    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
    notification.setLatestEventInfo(getApplicationContext(), getResources().getString(R.string.app_name), getResources().getString(R.string.notification_text), settingsIntent);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.FLAG_NO_CLEAR;

    m_notificationManager.notify(NOTIFICATION_ID, notification);
    startForeground(NOTIFICATION_ID, notification);
  }

  @Override
  public void onDestroy() {
    m_notificationManager.cancel(NOTIFICATION_ID);
    super.onDestroy();
  }

  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }
}




Java Source Code List

mobi.omegacentauri.p1keyboard.BGP100Reader.java
mobi.omegacentauri.p1keyboard.BluezDriverInterface.java
mobi.omegacentauri.p1keyboard.BluezForegroundService.java
mobi.omegacentauri.p1keyboard.BluezIMESettings.java
mobi.omegacentauri.p1keyboard.BluezIME.java
mobi.omegacentauri.p1keyboard.BluezService.java
mobi.omegacentauri.p1keyboard.ButtonConfiguration.java
mobi.omegacentauri.p1keyboard.DataDumpReader.java
mobi.omegacentauri.p1keyboard.DeviceScanActivity.java
mobi.omegacentauri.p1keyboard.FutureKeyCodes.java
mobi.omegacentauri.p1keyboard.GameStopReader.java
mobi.omegacentauri.p1keyboard.HIDKeyboard.java
mobi.omegacentauri.p1keyboard.HIDReaderBase.java
mobi.omegacentauri.p1keyboard.HIDipega.java
mobi.omegacentauri.p1keyboard.ImprovedBluetoothDevice.java
mobi.omegacentauri.p1keyboard.PalmOneWirelessKeyboardReader.java
mobi.omegacentauri.p1keyboard.PhonejoyReader.java
mobi.omegacentauri.p1keyboard.Preferences.java
mobi.omegacentauri.p1keyboard.RfcommReader.java
mobi.omegacentauri.p1keyboard.WiimoteReader.java
mobi.omegacentauri.p1keyboard.ZeemoteReader.java
mobi.omegacentauri.p1keyboard.iCadeReader.java
mobi.omegacentauri.p1keyboard.iControlPadReader.java