Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以从首选项片段xml启动蓝牙发现_Android_Xml_Android Fragments_Sharedpreferences - Fatal编程技术网

Android 是否可以从首选项片段xml启动蓝牙发现

Android 是否可以从首选项片段xml启动蓝牙发现,android,xml,android-fragments,sharedpreferences,Android,Xml,Android Fragments,Sharedpreferences,我有一个偏好片段,我正在尝试设置一个自定义偏好选项来做一些事情。起初,我在寻找一种添加itemclicklistener的方法,但使用PreferenceFragments似乎无法做到这一点 <Preference android:title="prefs_web_page" > <intent android:action="android.intent.action.VIEW" android:data="http://ww

我有一个偏好片段,我正在尝试设置一个自定义偏好选项来做一些事情。起初,我在寻找一种添加itemclicklistener的方法,但使用PreferenceFragments似乎无法做到这一点

 <Preference android:title="prefs_web_page" >
        <intent android:action="android.intent.action.VIEW"
                android:data="http://www.example.com" />
 </Preference>

使用上面的方法,我想这样的方法应该会奏效

   <Preference android:title="prefs_discover" >
   <intent android:action="android.intent.action.RUN"
         android:data ="BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE"/>
   </Preference>

我试过RUN和View,两种方法都不管用。甚至可以做我想做的事吗

如果有更有效的选择,我愿意接受建议

编辑:参见下面的讨论

我用一些代码做了一个活动来启动BT Discoverable,之后我立即使用finish();关闭活动,使用户永远看不到它

它很脏,但它能完成任务。仍然欢迎关于提高效率的建议等

mBTA = BluetoothAdapter.getDefaultAdapter();
    if (mBTA == null){
        return;
    }
    if (!mBTA.isEnabled()){
        Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBT, 0xDEADBEEF);
    }
    mBTA.startDiscovery();

但这不是一种偏好。

我应该澄清一下。我知道如何在课堂上做这件事,比如将它设置为启动,这是您的操作,或者单击按钮。但我需要它在一个选项片段中单击。奇怪的是,没有这样做的基本能力。它们有复选框、单选/选择列表等,但没有基本的执行操作。如果我在活动中输入此类代码,然后从“选项”菜单打开活动,可能会出现这种情况。是时候测试一下了,我不知道:P