当前位置: 首页>>代码示例>>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;未经允许,请勿转载。