将声音路由到蓝牙耳机

时间:2011-10-20 07:11:47

标签: android bluetooth

我需要紧急帮助解决我的项目问题。

我想将手机声音传送到蓝牙耳机。 Cleint已指示使用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不能访问它。

请给我一个解决问题的方法

0 个答案:

没有答案
相关问题