2012-05-10 8 views
1
public PluginResult execute(String action, JSONArray args, String callbackId) {   
    try { 
    Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG); 
    String nm = intent.getStringExtra("name"); 
    String st1 = intent.getStringExtra("state"); 
    Log.v("nikhil","i="+intent+" name="+nm+" 2="+st1); 

    return new PluginResult(PluginResult.Status.OK); 

    } catch(Exception e) {    

    Log.e("MailApp", "Could not send email", e); 
    } 
    return null; 
} 

nm 및 st1은 항상 null이됩니다. 헤드셋이 연결되어있는 경우에도 !!!Intent.ACTION_HEADSET_PLUG null null

답변

1

인 텐트 Intent.ACTION_HEADSET_PLUG는 핸드셋을 꽂거나 뺄 때 안드로이드 시스템에 의해 작동됩니다.

이 이벤트를 발생 시키려면 BroadcastReceiver를 구현해야합니다. 이것은 고정 이벤트이므로 다음 바로 가기를 사용할 수 있습니다.

IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); 
Intent headsetState= this.registerReceiver(null, filter); 
int state = headsetState.getIntExtra("state", -1); 
String name = headsetState.getStringExtra("name");