全部
我想在我的服务类中实现一个getSimstate()侦听器。我无法做到这一点。
我知道可以在Telephony类中使用sim侦听器来完成。但我没有得到任何代码来实现它。
如果有人有代码要听,那么枯萎已经准备好了......请给我......
答案 0 :(得分:2)
final TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
//Code in here executed when the sim state has changed
}
@Override
public void onDataConnectionStateChanged(int state) {
}
});
答案 1 :(得分:1)
<receiver
android:name=".SimChangedReceiver"
android:enabled="true"
android:process=":remote" >
<intent-filter>
<action android:name="android.intent.action.SIM_STATE_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
SimChangedReceiver类
public class SimChangedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase("android.intent.action.SIM_STATE_CHANGED")) {
Log.d("SimChangedReceiver", "--> SIM state changed <--");
}
}
}