안드로이드 소스 인데 블루투스를 검색해서 검색된 블루투스랑 변수랑 같으면 진동 하려고 하는데 안되네요 어떻게 해야 되죠 ㅠㅠ
분명 같은 String 같은데...
녹색으로 표시 해뒀음
아시는 전문가분분 꼭 답변좀 부탁 드립니다.
package com.cton;
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.os.Vibrator;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
// 단말기 검색 액티비티
public class DeviceListActivity extends Activity
implements AdapterView.OnItemClickListener {
public static String EXTRA_DEVICE_ADDRESS="device_address";
private BluetoothAdapter btAdapter; // BT 어댑터
private ArrayAdapter<String> devices; // 디바이스군
// 어플리케이션 생성 시 불린다.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setResult(Activity.RESULT_CANCELED);
// 레이아웃의 생성
LinearLayout layout=new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// 디바이스
devices=new ArrayAdapter<String>(this,R.layout.rowdata);
// 리스트 뷰의 생성
ListView listView=new ListView(this);
setLLParams(listView);
listView.setAdapter(devices);
layout.addView(listView);
listView.setOnItemClickListener(this);
// 브로드캐스트 리시버의 추가
IntentFilter filter;
filter=new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(receiver,filter);
filter=new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(receiver,filter);
// Bluetooth 단말기의 검색 시작 (2)
btAdapter=BluetoothAdapter.getDefaultAdapter();
// 등록된 디바이스를 등록
// Set<BluetoothDevice> pairedDevices=btAdapter.getBondedDevices();
// if (pairedDevices.size()>0) {
// for (BluetoothDevice device:pairedDevices) {
// devices.add(device.getName()+
// System.getProperty("line.separator")+
// device.getAddress()
// );
// }
// }
if (btAdapter.isDiscovering()) btAdapter.cancelDiscovery();
btAdapter.startDiscovery();
}
// 어플리케이션 파괴 시 불린다.
@Override
protected void onDestroy() {
super.onDestroy();
if (btAdapter!=null) btAdapter.cancelDiscovery();
this.unregisterReceiver(receiver);
}
// 클릭 시 불린다.
public void onItemClick(AdapterView<?>av,View v,int arg2,long arg3) {
String a = new String("00:15:83:4E:39:DC");
String b = "GM";
// Bluetooth 단말기의 검색 취소
btAdapter.cancelDiscovery();
// 반환값의 지정
String info =(((TextView) v).getText().toString());
String address=info.substring(info.length()-17);
info=info.substring(0, info.length()-18);
Intent intent =new Intent(this,NoteEdit.class);
intent.putExtra("infos",info);
intent.putExtra("add",address);
setResult(RESULT_OK, intent);
finish();
startActivity(intent);
}
// 리니어 레이아웃의 파라미터 지정
private static void setLLParams(View view) {
view.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
}
// 브로드캐스트 리시버
private final BroadcastReceiver receiver=new BroadcastReceiver() {
String a = "00:15:83:4E:39:DC";
String b = "GM";
// Bluetooth 단말기의 검색 결과 취득 (3)
@Override
public void onReceive(Context context, Intent intent) {
String action=intent.getAction();
BluetoothDevice device=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Bluetooth 단말기 발견
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
if (device.getBondState()!=BluetoothDevice.BOND_BONDED) {
devices.add(device.getName()+
System.getProperty("line.separator")+
device.getAddress());
if (device.getAddress()==a){
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(500);
}
Toast.makeText(DeviceListActivity.this,device.getAddress() , 0).show();
}
}
// Bluetooth 단말기 검색 완료
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
android.util.Log.e("","Bluetooth ");
}
}
};
}
소스를 어디서 얻으셨는진 모르겠지만.. String 을 == 로 비교하시면 안되죠. equals 나 compareTo 로 비교하세요.