package com.example.headsetinout;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class sv extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
Log.i("Check", "HP");
int headSetState = intent.getIntExtra("state", 0); // get the
// headset state
// property
if (headSetState == 0)
Toast.makeText(context, "headset unplug", Toast.LENGTH_LONG)
.show();
else
Toast.makeText(context, "headset plug", Toast.LENGTH_LONG)
.show();
}
}
}
-----------------------------------------------------------------------------------------------------
broadcast receiver,
沒有留言:
張貼留言