「android開発」Androidからイヤフォンステータスを判断する方法
Javaコード:
public class ServiceReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
try {
if (intent.getIntExtra(“state", 0) == 0) {
Log.e(“caculate broadcast", “headset off");
bHeadsetOn = false;
} else if (intent.getIntExtra(“state", 0) == 1) {
Log.e(“headset", “headset on");
bHeadsetOn = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}