List of usage examples for android.content Context BIND_ABOVE_CLIENT
int BIND_ABOVE_CLIENT
To view the source code for android.content Context BIND_ABOVE_CLIENT.
Click Source Link
From source file:edu.umich.oasis.client.OASISConnection.java
public static ServiceConnection bind(final Context context, final Callback callback) { final ServiceConnection connection = new ServiceConnection() { private OASISConnection conn; @Override//from w w w . j a v a 2 s . co m public void onServiceConnected(ComponentName componentName, IBinder iBinder) { IOASISService service = IOASISService.Stub.asInterface(iBinder); conn = new OASISConnection(context, this, service); try { callback.onConnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onConnect", e); } } @Override public void onServiceDisconnected(ComponentName componentName) { Log.e(TAG, "Lost Binder connection to OASIS"); if (callback instanceof DisconnectCallback) { try { ((DisconnectCallback) callback).onDisconnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onDisconnect", e); } } conn.closeInternal(); } }; Intent serviceIntent = new Intent(); serviceIntent.setComponent(OASISFramework.getServiceComponent(context)); if (context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE | Context.BIND_ADJUST_WITH_ACTIVITY | Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) { return connection; } else { return null; } }
From source file:me.ziccard.secureit.fragment.MicrophoneFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prefs = new SecureItPreferences(getActivity()); if (prefs.getMicrophoneSensitivity().equals("High")) { NOISE_THRESHOLD = 30.0;//from w w w .j a v a2s . c o m } else if (prefs.getMicrophoneSensitivity().equals("Medium")) { NOISE_THRESHOLD = 40.0; } getActivity().bindService(new Intent(getActivity(), UploadService.class), mConnection, Context.BIND_ABOVE_CLIENT); try { microphone = MicrophoneTaskFactory.makeSampler(getActivity()); microphone.setMicListener(this); microphone.execute(); } catch (RecordLimitExceeded e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.continuesvoicerecognition.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent service = new Intent(getBaseContext(), SpeechRecognizerService.class); getBaseContext().startService(service); mBindFlag = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ? 0 : Context.BIND_ABOVE_CLIENT; receiver = new BroadcastReceiver() { @Override// ww w.j av a 2 s . c om public void onReceive(Context context, Intent intent) { String s = intent.getStringExtra(SpeechRecognizerService.RECOGNIZER_MESSAGE); result_tv.setText(s); } }; setContentView(R.layout.activity_main); findViews(); setClickListeners(); }
From source file:com.javadog.cgeowear.CompassActivity.java
private void bindToService() { if (!serviceBound) { Intent bindIntent = new Intent(this, cgeoWearService.class); bindService(bindIntent, serviceConnection, Context.BIND_ABOVE_CLIENT); }/*w w w.j av a2s .c o m*/ }
From source file:de.ncoder.sensorsystem.android.app.MainActivity.java
@Override public void onResume() { super.onResume(); Intent service = new Intent(this, SensorSystemService.class); if (bindService(service, connection, Context.BIND_ABOVE_CLIENT)) { bound = true;/*from w w w . ja v a2s .c o m*/ } else { Log.w(TAG, "SensorSystem Service bind failed"); } }
From source file:me.ziccard.secureit.fragment.AccelerometerFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prefs = new SecureItPreferences(getActivity()); /*//from ww w . java 2s .co m * Set sensitivity value */ if (prefs.getAccelerometerSensitivity().equals("Medium")) { SHAKE_THRESHOLD = 2700; Log.i("AccelerometerFragment", "Sensitivity set to 2700"); } else if (prefs.getAccelerometerSensitivity().equals("Low")) { SHAKE_THRESHOLD = 3100; Log.i("AccelerometerFragment", "Sensitivity set to 3100"); } else { SHAKE_THRESHOLD = 2300; Log.i("AccelerometerFragment", "Sensitivity set to 2300"); } getActivity().bindService(new Intent(getActivity(), UploadService.class), mConnection, Context.BIND_ABOVE_CLIENT); }
From source file:indrora.atomic.activity.ConversationActivity.java
/** * On resume/*from w w w . j av a2 s . co m*/ */ @Override public void onResume() { // register the receivers as early as possible, otherwise we may loose a // broadcast message channelReceiver = new ConversationReceiver(server.getId(), this); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_TOPIC)); serverReceiver = new ServerReceiver(this); registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE)); super.onResume(); // Check if speech recognition is enabled and available if (new Settings(this).isVoiceRecognitionEnabled()) { PackageManager pm = getPackageManager(); Button speechButton = (Button) findViewById(R.id.speech); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this)); speechButton.setVisibility(View.VISIBLE); } } // Start service Intent intent = new Intent(this, IRCService.class); intent.setAction(IRCService.ACTION_FOREGROUND); startService(intent); int flags = 0; if (android.os.Build.VERSION.SDK_INT > 13) { flags |= Context.BIND_ABOVE_CLIENT; flags |= Context.BIND_IMPORTANT; } bindService(intent, this, flags); // Let's be explicit about this. ((EditText) findViewById(R.id.input)).setEnabled(true); // Optimization - cache field lookup Collection<Conversation> mConversations = server.getConversations(); MessageListAdapter mAdapter; // Fill view with messages that have been buffered while paused for (Conversation conversation : mConversations) { String name = conversation.getName(); mAdapter = pagerAdapter.getItemAdapter(name); if (mAdapter != null) { mAdapter.addBulkMessages(conversation.getBuffer()); conversation.clearBuffer(); } else { // Was conversation created while we were paused? if (pagerAdapter.getPositionByName(name) == -1) { onNewConversation(name); } } // Clear new message notifications for the selected conversation if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) { Intent ackIntent = new Intent(this, IRCService.class); ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS); ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId); ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, name); startService(ackIntent); } } // Remove views for conversations that ended while we were paused int numViews = pagerAdapter.getCount(); if (numViews > mConversations.size()) { for (int i = 0; i < numViews; ++i) { if (!mConversations.contains(pagerAdapter.getItem(i))) { pagerAdapter.removeConversation(i--); --numViews; } } } // Join channel that has been selected in JoinActivity // (onActivityResult()) if (joinChannelBuffer != null) { new Thread() { @Override public void run() { binder.getService().getConnection(serverId).joinChannel(joinChannelBuffer); joinChannelBuffer = null; } }.start(); } setupColors(); setupIndicator(); openSoftKeyboard(findViewById(R.id.input)); server.setIsForeground(true); }