2012-09-03 5 views
0

내 안드로이드 장치의 기본 홈 화면으로 내 응용 프로그램 홈 화면이 있습니다. 내 응용 프로그램에 상태 표시 줄이 있고 해당 상태 표시 줄에있는 Imageview (onclick)를 사용하여 Bluetooth 연결 상태를 관리하고 있습니다.상태 표시 줄의 블루투스 상태

내 상태 표시 줄의 Imageview를 클릭하면 블루투스를 켜거나 끕니다. 나는 블루투스의 상태에 따라 imageview의 배경을 바꾸고있다.

블루투스가 ON 인 경우 - Blueimage

블루투스가 꺼져있는 경우 - greyImage

그래서 내 질문입니다 - 내가 사용/사용하면 bluetoth 설정 페이지에서 블루투스를 해제하고 다시 버튼을 누르면 내 집으로 이동 화면에서 내 상태 표시 줄의 이미지 뷰 (배경 이미지)가 자동으로 변경됩니다.

다시 버튼 누르기 (onbackpressed 메서드 무시)로 imageview 이미지를 많이 업데이트하려고했지만 결과가 없습니다.

블루투스 설정 페이지에서 블루투스를 사용/사용 중지하는 즉시 변수에 블루투스 상태를 읽고 저장할 수있는 유사한 API가 있습니까? 따라서 상태 표시 줄 imageview backround가 자동으로 변경됩니다.

어떤 도움이 크게 감사합니다, 감사합니다

답변

0
당신이 onRestart() 메소드에서 Bluetooth 상태에 대한이 같은

확인 코드를 넣을 수 있습니다

:

public class yourClass { 

public void onCreate(Bundle savedInstanceState) { 

// your code 
} 

public void onRestart() { 

// put the checked code for the Bluetooth status here 
} 
+0

답장을 보내 주셔서 감사합니다. 이미지보기가 변경되지 않습니다. (설정 페이지에서 블루투스를 활성화하고 다시 버튼을 눌렀습니다.) – Randroid

0

당신은 추가 할 필요를 귀하의 코드에서 브로드 캐스트 수신자가 귀하의 액티비티 클래스에서 켜지거나 꺼져있을 때 브로드 캐스트 리시버를 수신하십시오. 참조 용 :

public void onCreate() { 

    IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); 
    IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); 
    IntentFilter filter3 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); 
    this.registerReceiver(mReceiver, filter1); 
    this.registerReceiver(mReceiver, filter2); 
    this.registerReceiver(mReceiver, filter3); 

}

// 블루투스 방송

private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 

     if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
     ... //Device found 
     } 
     else if (BluetoothAdapter.ACTION_ACL_CONNECTED.equals(action)) { 
     ... //Device is now connected 
     } 
     else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { 
     ... //Done searching 
     } 
     else if (BluetoothAdapter.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) { 
     ... //Device is about to disconnect 
     } 
     else if (BluetoothAdapter.ACTION_ACL_DISCONNECTED.equals(action)) { 
     ... //Device has disconnected 
     } 

당신이 상태를 수신하는 즉시를받는 브로드 캐스트 리시버는 기능 ... 수행 않습니다!

+0

고마워요.하지만 상태 표시 줄의 이미지 뷰를 업데이트하려고합니다. 내가 블루투스 설정 페이지에서 블루투스를 활성화/비활성화하면 내 장치의 '뒤로'버튼을 사용할 수 있습니다. – Randroid

+0

왜 그렇게하고 싶어 ?? onBackPressed()를 재정의하는 동안 super.onBackPressed()를 제거해야 할 필요가 있음을 기억하십시오. 그렇지 않으면 활동이 파괴됩니다! –

+0

내 질문에 내가 위에서 언급 한 동일한 언급, 내 장치에 대한 기본 홈 화면으로 설정하고 내 자신의 응용 프로그램을 지금 언급 한 경우 블루투스 설정 페이지에서 및 뒤로 단추를 누르면 ImageView 변경해야합니다 상태 바 (Imageview 배경에 2 개의 .png 파일을 사용 중이며, 하나는 ON, 하나는 OFF) – Randroid

관련 문제