Ciao sto lavorando su un'applicazione che genera un evento quando la cuffia viene rimossa dal telefono cellulare. Ho creato un ricevitore di broadcast con ricevere MetodoBroadcastReceiver per scollegare la cuffia
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
Log.i("Broadcast Receiver", "Hello");
if((action.compareTo(Intent.ACTION_HEADSET_PLUG)) == 0) //if the action match a headset one
{
int headSetState = intent.getIntExtra("state", 0); //get the headset state property
int hasMicrophone = intent.getIntExtra("microphone", 0);//get the headset microphone property
if((headSetState == 0) && (hasMicrophone == 0)) //headset was unplugged & has no microphone
{
//do whatever
}
}
}
chiamata a questo metodo come segue
IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
HeadSetBroadCastReceiver receiver = new HeadSetBroadCastReceiver();
registerReceiver(receiver, receiverFilter);
anche io ho registrare questo si manifestano come
<receiver android:name=".HeadsetBroadCastReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_HEADSET_PLUG"/>
</intent-filter>
</receiver>
e il permesso
Ma questo non funziona può tu mi guidi attraverso questo?
Ragazzi comuni nessuno mi può guidare? – Sumit
[Controlla questo] (http: // StackOverflow.it/questions/4092438/intent-action-headset-plug-is-received-when-activity-starts) –
[Questo funziona] (http://stackoverflow.com/a/6366238/726863) –