展会信息港展会大全

Android怎样设置蓝牙可见性
来源:互联网   发布日期:2015-09-28 15:49:12   浏览:2493次  

导读:package zhang.bluetooth; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; impor......

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 蓝牙 设置

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港