将声音路由至蓝牙耳机
我想将手机声音传送到蓝牙耳机。客户端已指示使用 iBluetoothA2DP 接口。但是使用 a2dp.connectSink() 请求 write_secure 设置权限,但该权限不可用。
请建议我一种方法,以防 iBluetoothA2Dp 无法实现。
这是我的代码
private IBluetoothA2dp getIBluetoothA2dp() {
IBluetoothA2dp ibta = null;
try {
Class<?> c2 = Class.forName("android.os.ServiceManager");
Method m2 = c2.getDeclaredMethod("getService", String.class);
IBinder b = (IBinder) m2.invoke(null, "bluetooth_a2dp");
Class<?> c3 = Class.forName("android.bluetooth.IBluetoothA2dp");
Class<?> c = c3.getDeclaredClasses()[0];
Method m = c.getDeclaredMethod("asInterface", IBinder.class);
m.setAccessible(true);
ibta = (IBluetoothA2dp) m.invoke(null, b);
} catch (Exception e) {
toast("IBluetoothA2dp: " + e.toString());
}
return ibta;
}
这是我正在做的事情
private void connectA2dp(boolean connect)
{
try
{
if (connect)
a2dp.connectSink(device);
else
a2dp.disconnectSink(device);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}
编译器告诉我包含 write_secure _settings 权限,我无法使用该权限,因为 Android 不允许访问它。
I want to route my phone sound to Bluetooth Headset. Client has directed to use iBluetoothA2DP interface. But using a2dp.connectSink() asking for write_secure settings permission which is not available.
Please suggest me a way in case iBluetoothA2Dp is not possible.
Here is my code
private IBluetoothA2dp getIBluetoothA2dp() {
IBluetoothA2dp ibta = null;
try {
Class<?> c2 = Class.forName("android.os.ServiceManager");
Method m2 = c2.getDeclaredMethod("getService", String.class);
IBinder b = (IBinder) m2.invoke(null, "bluetooth_a2dp");
Class<?> c3 = Class.forName("android.bluetooth.IBluetoothA2dp");
Class<?> c = c3.getDeclaredClasses()[0];
Method m = c.getDeclaredMethod("asInterface", IBinder.class);
m.setAccessible(true);
ibta = (IBluetoothA2dp) m.invoke(null, b);
} catch (Exception e) {
toast("IBluetoothA2dp: " + e.toString());
}
return ibta;
}
Here is what i m doing
private void connectA2dp(boolean connect)
{
try
{
if (connect)
a2dp.connectSink(device);
else
a2dp.disconnectSink(device);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}
The compiler is telling me to include write_secure _settings permission which I can't use as Android not give access to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论