當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothProfile.ServiceListener方法代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothProfile.ServiceListener方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothProfile.ServiceListener方法的具體用法?Java BluetoothProfile.ServiceListener怎麽用?Java BluetoothProfile.ServiceListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.BluetoothProfile的用法示例。


在下文中一共展示了BluetoothProfile.ServiceListener方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startBluetooth

import android.bluetooth.BluetoothProfile; //導入方法依賴的package包/類
private void startBluetooth() {
	if (isBluetoothConnected) {
		Log.e("[Bluetooth] Already started, skipping...");
		return;
	}
	
	mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	
	if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
		if (mProfileListener != null) {
			Log.w("[Bluetooth] Headset profile was already opened, let's close it");
			mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
		}
		
		mProfileListener = new BluetoothProfile.ServiceListener() {
			public void onServiceConnected(int profile, BluetoothProfile proxy) {
			    if (profile == BluetoothProfile.HEADSET) {
			        Log.d("[Bluetooth] Headset connected");
			        mBluetoothHeadset = (BluetoothHeadset) proxy;
			        isBluetoothConnected = true;
			    }
			}
			public void onServiceDisconnected(int profile) {
			    if (profile == BluetoothProfile.HEADSET) {
			        mBluetoothHeadset = null;
			        isBluetoothConnected = false;
			        Log.d("[Bluetooth] Headset disconnected");
			        LinphoneManager.getInstance().routeAudioToReceiver();
			    }
			}
		};
		boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET);
		if (!success) {
			Log.e("[Bluetooth] getProfileProxy failed !");
		}
	} else {
		Log.w("[Bluetooth] Interface disabled on device");
	}
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:40,代碼來源:BluetoothManager.java

示例2: getBluetoothProfileProxy

import android.bluetooth.BluetoothProfile; //導入方法依賴的package包/類
protected boolean getBluetoothProfileProxy(
        Context context, BluetoothProfile.ServiceListener listener, int profile) {
    return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
開發者ID:nhancv,項目名稱:nc-android-webrtcpeer,代碼行數:5,代碼來源:BluetoothManager.java

示例3: getBluetoothProfileProxy

import android.bluetooth.BluetoothProfile; //導入方法依賴的package包/類
protected boolean getBluetoothProfileProxy(
    Context context, BluetoothProfile.ServiceListener listener, int profile) {
  return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:5,代碼來源:AppRTCBluetoothManager.java

示例4: setUp

import android.bluetooth.BluetoothProfile; //導入方法依賴的package包/類
@Before
public void setUp() {
    ShadowLog.stream = System.out;
    context = ShadowApplication.getInstance().getApplicationContext();
    mockedAppRtcAudioManager = mock(AppRTCAudioManager.class);
    mockedAudioManager = mock(AudioManager.class);
    mockedBluetoothHeadset = mock(BluetoothHeadset.class);
    mockedBluetoothDevice = mock(BluetoothDevice.class);
    mockedBluetoothDeviceList = new LinkedList<BluetoothDevice>();

    // Simulate that bluetooth SCO audio is available by default.
    when(mockedAudioManager.isBluetoothScoAvailableOffCall()).thenReturn(true);

    // Create the test object and override protected methods for this test.
    bluetoothManager = new AppRTCBluetoothManager(context, mockedAppRtcAudioManager) {
        @Override
        protected AudioManager getAudioManager(Context context) {
            Log.d(TAG, "getAudioManager");
            return mockedAudioManager;
        }

        @Override
        protected void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
            Log.d(TAG, "registerReceiver");
            if (filter.hasAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
                    && filter.hasAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
                // Gives access to the real broadcast receiver so the test can use it.
                bluetoothHeadsetStateReceiver = receiver;
            }
        }

        @Override
        protected void unregisterReceiver(BroadcastReceiver receiver) {
            Log.d(TAG, "unregisterReceiver");
            if (receiver == bluetoothHeadsetStateReceiver) {
                bluetoothHeadsetStateReceiver = null;
            }
        }

        @Override
        protected boolean getBluetoothProfileProxy(
                Context context, BluetoothProfile.ServiceListener listener, int profile) {
            Log.d(TAG, "getBluetoothProfileProxy");
            if (profile == BluetoothProfile.HEADSET) {
                // Allows the test to access the real Bluetooth service listener object.
                bluetoothServiceListener = listener;
            }
            return true;
        }

        @Override
        protected boolean hasPermission(Context context, String permission) {
            Log.d(TAG, "hasPermission(" + permission + ")");
            // Ensure that the client asks for Bluetooth permission.
            return (permission == android.Manifest.permission.BLUETOOTH);
        }

        @Override
        protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
            // Do nothing in tests. No need to mock BluetoothAdapter.
        }
    };
}
 
開發者ID:lgyjg,項目名稱:AndroidRTC,代碼行數:64,代碼來源:BluetoothManagerTest.java


注:本文中的android.bluetooth.BluetoothProfile.ServiceListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。