android-设置蓝牙的可见性
2011-08-02 23:39
405 查看
老规矩。右键取得图片地址,利用下载工具下载这个显示不出来的图片。后缀改为rar即可得到源代码项目。
package zhang.bluetooth; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class bluetooth_02 extends Activity { @Override protected void onDestroy() { // TODO Auto-generated method stub unregisterReceiver(bluetoothReceiver); super.onDestroy(); } private Button set; private Button scan; private BluetoothReceiver bluetoothReceiver =null; private BluetoothAdapter bluetoothAdapter=null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); set=(Button)findViewById(R.id.set); scan=(Button)findViewById(R.id.scan); set.setOnClickListener(new setListener()); IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); bluetoothReceiver = new BluetoothReceiver(); System.out.println(scan); scan.setOnClickListener(new scanListener()); } public class BluetoothReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action =intent.getAction(); if(BluetoothDevice.ACTION_FOUND.equals(action)){ BluetoothDevice device=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); System.out.println(device.getAddress()); } } } class setListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent dis=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); dis.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 500); startActivity(dis); } } class scanListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub //与之前的类似 } } }
相关文章推荐
- 关于android蓝牙可见性设置
- Android通过反射机制实现后台设置蓝牙可见性
- ANDROID_MARS学习笔记_S03_002_设置可见性及扫描蓝牙设备
- android系统app打开蓝牙+设置可见性
- 关于android蓝牙开发中 蓝牙可见性设置
- Android蓝牙设置连接
- Android中设置控件可见与不可见详解
- Android中设置控件可见与不可见详解
- Android 设置中的蓝牙
- android动态设置EditText的password内容可不可见
- Android开发之蓝牙(Bluetooth)操作(二)--修改本机蓝牙设备的可见性,并扫描周围可用的蓝牙设备
- 如何从后台开启android蓝牙的可见性以及始终保持可见性
- Android EditText 密码输入框可见性设置
- Android中设置控件可见与不可见
- Android EditText 密码输入框可见性设置
- android控件可见性设置
- Android EditText 设置密码可见性(查看密码按钮的实现)
- Android中设置控件可见与不可见详解
- Android菜鸟开发之蓝牙(Bluetooth)---设置应用源码分析
- Android中设置控件可见与不可见详解