本文整理汇总了Java中android.bluetooth.BluetoothA2dp类的典型用法代码示例。如果您正苦于以下问题:Java BluetoothA2dp类的具体用法?Java BluetoothA2dp怎么用?Java BluetoothA2dp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothA2dp类属于android.bluetooth包,在下文中一共展示了BluetoothA2dp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: btA2dpConnect
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@RpcMinSdk(Build.VERSION_CODES.KITKAT)
@Rpc(
description =
"Connects to a paired or discovered device with A2DP profile."
+ "If a device has been discovered but not paired, this will pair it."
)
public void btA2dpConnect(String deviceAddress) throws Throwable {
BluetoothDevice device = BluetoothAdapterSnippet.getKnownDeviceByAddress(deviceAddress);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
mContext.registerReceiver(new PairingBroadcastReceiver(mContext), filter);
Utils.invokeByReflection(sA2dpProfile, "connect", device);
if (!Utils.waitUntil(
() -> sA2dpProfile.getConnectionState(device) == BluetoothA2dp.STATE_CONNECTED,
120)) {
throw new BluetoothA2dpSnippetException(
"Failed to connect to device "
+ device.getName()
+ "|"
+ device.getAddress()
+ " with A2DP profile within 2min.");
}
}
示例2: handleBtConnectState
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
/**
* handle FM over BT connect state
*
* @param connectState
* FM over BT connect state
*/
private void handleBtConnectState(int connectState) {
if (!mIsPowerUp) {
return;
}
switch (connectState) {
case BluetoothA2dp.STATE_CONNECTED:
//case BluetoothA2dp.STATE_PLAYING:
//case BluetoothA2dp.STATE_CONNECTING:
Log.d(TAG, "handleBtConnectState bt connected");
changeToEarphoneMode();
break;
case BluetoothA2dp.STATE_DISCONNECTED:
//case BluetoothA2dp.STATE_DISCONNECTING:
Log.d(TAG, "handleBtConnectState bt disconnected");
changeToEarphoneMode();
break;
default:
Log.d(TAG, "invalid fm over bt connect state");
break;
}
}
示例3: registerFmBroadcastReceiver
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
private void registerFmBroadcastReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(SOUND_POWER_DOWN_MSG);
filter.addAction(Intent.ACTION_SHUTDOWN);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_HEADSET_PLUG);
/* Vanzo:tanglei on: Fri, 13 Mar 2015 21:22:01 +0800
*/
//if (FeatureOption.VANZO_FEATURE_EARPHONE_KEY_ACTION) {
// filter.addAction("com.mediatek.FMRadio.FMRadioService.NEXT_STATION");
//}
// End of Vanzo:tanglei
filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(ACTION_TOFMSERVICE_POWERDOWN);
filter.addAction(ACTION_FROMATVSERVICE_POWERUP);
mBroadcastReceiver = new FmServiceBroadcastReceiver();
Log.i(TAG, "Register broadcast receiver.");
registerReceiver(mBroadcastReceiver, filter);
}
示例4: onServiceConnected
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
Log.e("blueHeadsetListener", "onServiceConnected:" + profile);
if (profile == BluetoothProfile.A2DP) {
voiceMediator.setBluetoothA2dp((BluetoothA2dp) proxy);
} else if (profile == BluetoothProfile.HEADSET) {
voiceMediator.setBluetoothHeadset((BluetoothHeadset) proxy);
}
}
示例5: btA2dpDisconnect
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Rpc(description = "Disconnects a device from A2DP profile.")
public void btA2dpDisconnect(String deviceAddress) throws Throwable {
BluetoothDevice device = getConnectedBluetoothDevice(deviceAddress);
Utils.invokeByReflection(sA2dpProfile, "disconnect", device);
if (!Utils.waitUntil(
() -> sA2dpProfile.getConnectionState(device) == BluetoothA2dp.STATE_DISCONNECTED,
120)) {
throw new BluetoothA2dpSnippetException(
"Failed to disconnect device "
+ device.getName()
+ "|"
+ device.getAddress()
+ " from A2DP profile within 2min.");
}
}
示例6: onServiceConnected
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
try {
if (profile == BluetoothProfile.HEADSET) {
// bh = (BluetoothHeadset) proxy;
// if (bh.getConnectionState(mTouchObject.bluetoothDevice) != BluetoothProfile.STATE_CONNECTED){
// bh.getClass()
// .getMethod("connect", BluetoothDevice.class)
// .invoke(bh, mTouchObject.bluetoothDevice);
// }
} else if (profile == BluetoothProfile.A2DP) {
/**使用A2DP的协议连接蓝牙设备(使用了反射技术调用连接的方法)*/
a2dp = (BluetoothA2dp) proxy;
if (a2dp.getConnectionState(currentBluetoothDevice) != BluetoothProfile.STATE_CONNECTED) {
a2dp.getClass()
.getMethod("connect", BluetoothDevice.class)
.invoke(a2dp, currentBluetoothDevice);
Toast.makeText(MainActivity.this,"请播放音乐",Toast.LENGTH_SHORT).show();
getBondedDevices();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: getConnectMethod
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
/**
* Wrapper around some reflection code to get the hidden 'connect()' method
* @return the connect(BluetoothDevice) method, or null if it could not be found
*/
private Method getConnectMethod () {
try {
return BluetoothA2dp.class.getDeclaredMethod("connect", BluetoothDevice.class);
} catch (NoSuchMethodException ex) {
Log.e(TAG, "Unable to find connect(BluetoothDevice) method in BluetoothA2dp proxy.");
return null;
}
}
示例8: setBluetoothA2dp
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
public void setBluetoothA2dp(BluetoothA2dp bluetoothA2dp) {
this.bluetoothA2dp = bluetoothA2dp;
}
示例9: getBluetoothA2dp
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public BluetoothA2dp getBluetoothA2dp() {
return bluetoothA2dp;
}
示例10: onServiceConnected
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
public void onServiceConnected(int var1, BluetoothProfile profile) {
sA2dpProfile = (BluetoothA2dp) profile;
sIsA2dpProfileReady = true;
}
示例11: onServiceConnected
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
bluetoothHandler
.obtainMessage(BluetoothHandler.MESSAGE_A2DP_PROXY_RECEIVED,(BluetoothA2dp) bluetoothProfile)
.sendToTarget();
}
示例12: handleMessage
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public void handleMessage(Message message) {
switch (message.what) {
case MESSAGE_READ:
byte[] readBuf = (byte[]) message.obj;
//get how many bytes were actually read.
int datalength = message.arg1;
String readMessage = new String(readBuf, 0, datalength);
if(readBuf.length > 0) {
if(mListener != null)
mListener.onBluetoothDataReceived(readBuf, readMessage);
}
break;
case MESSAGE_WAIT_FOR_CONNECTION:
if(dialog != null) {
dialog.setTitle("");
dialog.setMessage("Waiting...");
dialog.show();
}
break;
case MESSAGE_CONNECTION_MADE:
if(dialog != null) {
if(dialog.isShowing()) {
dialog.dismiss();
if(shouldShowSnackbars && mActivity != null) {
Snackbar.make(mActivity.findViewById(android.R.id.content), "Device connected.",
Snackbar.LENGTH_SHORT).show();
}
}
}
break;
case MESSAGE_A2DP_PROXY_RECEIVED:
BluetoothA2dp device = (BluetoothA2dp) message.obj;
if(device != null && mListener != null) {
mListener.onBluetoothA2DPRequested(device);
}
break;
default:
break;
}
}
示例13: onServiceConnected
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
@Override
public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
if (mCallback != null) {
mCallback.onA2DPProxyReceived((BluetoothA2dp) bluetoothProfile);
}
}
示例14: getBluetoothA2dp
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
/**
* 获取可操控蓝牙设备对象
**/
BluetoothA2dp getBluetoothA2dp();
示例15: onBluetoothA2DPRequested
import android.bluetooth.BluetoothA2dp; //导入依赖的package包/类
/**
* Called when a request is made to connect to an A2dp device.
* @param bluetoothA2dp the a2dp device.
*/
public void onBluetoothA2DPRequested(BluetoothA2dp bluetoothA2dp) {
}