public ServiceStateAssert hasState(@ServiceStateState int state) { isNotNull(); int actualState = actual.getState(); //noinspection ResourceType assertThat(actualState) // .overridingErrorMessage("Expected state <%s> but was <%s>.", serviceStateToString(state), serviceStateToString(actualState)) // .isEqualTo(state); return this; }
@Test @Config(minSdk = O) public void shouldSetServiceState() { ServiceState serviceState = new ServiceState(); serviceState.setState(ServiceState.STATE_OUT_OF_SERVICE); shadowOf(telephonyManager).setServiceState(serviceState); assertEquals(serviceState, telephonyManager.getServiceState()); }
public ServiceStateAssert isAutomaticSelection() { isNotNull(); assertThat(actual.getIsManualSelection()) // .overridingErrorMessage("Expected to have automatic selection mode but had manual.") // .isFalse(); return this; }
private void report(MessageWritable writer, ServiceState state) { Log.i(TAG, String.format("Phone state is %s; %s; %s", stateLabel(state.getState()), state.getIsManualSelection() ? "manual" : "automatic", state.getOperatorAlphaLong() == null ? "no operator" : "operator " + state.getOperatorAlphaLong() )); Wire.PhoneStateEvent.Builder message = Wire.PhoneStateEvent.newBuilder() .setState(stateLabel(state.getState())) .setManual(state.getIsManualSelection()); if (state.getOperatorAlphaLong() != null) { message.setOperator(state.getOperatorAlphaLong()); } writer.write(Wire.Envelope.newBuilder() .setType(Wire.MessageType.EVENT_PHONE_STATE) .setMessage(message.build().toByteString()) .build()); }
@Override public void onServiceStateChanged(ServiceState serviceState) { super.onServiceStateChanged(serviceState); final int state = serviceState.getState(); if (state == ServiceState.STATE_IN_SERVICE || state == ServiceState.STATE_POWER_OFF) { final boolean roamingState = serviceState .getRoaming(); if (roamingState != isRoamingOn()) { setRoamingOn(roamingState); } } } };
//declare current state ServiceState myServiceState = new ServiceState(); PhoneStateListener listener = null; // not sure if this is needed really.. // nifty getter public ServiceState getServiceState(){ return myServiceState; } //setup listener (eg. in onCreate) TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE); listener = new PhoneStateListener() { @Override public void onServiceStateChanged(ServiceState serviceState){ myServiceState = serviceState; } }; tm.listen(listener,PhoneStateListener.LISTEN_SERVICE_STATE); // to be called when destroying your context public void unregisterListener(){ // something like.. tm.listen(listener,PhoneStateListener.LISTEN_NONE); } //check service ServiceState pstate = getServiceState(); if(pstate.getState() != ServiceState.STATE_IN_SERVICE) { Log.v(TAG,"service state" +pstate.getState()); Toast.makeText(Myactivity.this, "error string", 2000).show(); return; }
public ServiceStateAssert isRoaming() { isNotNull(); assertThat(actual.getRoaming()) // .overridingErrorMessage("Expected to be in roaming but was not.") // .isTrue(); return this; }
mcc = Integer.parseInt(new ServiceState().getOperatorNumeric().substring(0, 3));
public void onClick(View v) { // check current state first boolean state = isAirplaneMode(); // toggle the state toggleAirplaneMode(state); state = isAirplaneMode(); // toggle the state toggleAirplaneMode(state); ser = new ServiceState(); ser.setState(STATE_IN_SERVICE); }
public ServiceStateAssert hasOperatorAlphaLong(String operatorAlphaLong) { isNotNull(); String actualOperatorAlphaLong = actual.getOperatorAlphaLong(); assertThat(actualOperatorAlphaLong) // .overridingErrorMessage( "Expected operator name in long alphanumeric format <%s> but was <%s>.", operatorAlphaLong, actualOperatorAlphaLong) // .isEqualTo(operatorAlphaLong); return this; }
public ServiceStateAssert hasOperatorNumeric(String operatorNumeric) { isNotNull(); String actualOperatorNumeric = actual.getOperatorNumeric(); assertThat(actualOperatorNumeric) // .overridingErrorMessage("Expected operator numeric ID <%s> but was <%s>.", operatorNumeric, actualOperatorNumeric) // .isEqualTo(operatorNumeric); return this; }
public ServiceStateAssert hasOperatorAlphaShort(String operatorAlphaShort) { isNotNull(); String actualOperatorAlphaShort = actual.getOperatorAlphaShort(); assertThat(actualOperatorAlphaShort) // .overridingErrorMessage( "Expected operator name in short alphanumeric format <%s> but was <%s>.", operatorAlphaShort, actualOperatorAlphaShort) // .isEqualTo(operatorAlphaShort); return this; }
public ServiceStateAssert isNotRoaming() { isNotNull(); assertThat(actual.getRoaming()) // .overridingErrorMessage("Expected to not be in roaming but was.") // .isFalse(); return this; }
public class SampleBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if(intent.getAction() != null) { Toast.makeText(context, ""+intent.getAction(), Toast.LENGTH_LONG); Log.d("onReceive","intent.getAction():::"+intent.getAction()); if(intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) { ServiceState _state = new ServiceState(); } } } }
public ServiceStateAssert hasOperatorAlphaLong(String operatorAlphaLong) { isNotNull(); String actualOperatorAlphaLong = actual.getOperatorAlphaLong(); assertThat(actualOperatorAlphaLong) // .overridingErrorMessage( "Expected operator name in long alphanumeric format <%s> but was <%s>.", operatorAlphaLong, actualOperatorAlphaLong) // .isEqualTo(operatorAlphaLong); return this; }
public ServiceStateAssert hasOperatorNumeric(String operatorNumeric) { isNotNull(); String actualOperatorNumeric = actual.getOperatorNumeric(); assertThat(actualOperatorNumeric) // .overridingErrorMessage("Expected operator numeric ID <%s> but was <%s>.", operatorNumeric, actualOperatorNumeric) // .isEqualTo(operatorNumeric); return this; }
public ServiceStateAssert hasOperatorAlphaShort(String operatorAlphaShort) { isNotNull(); String actualOperatorAlphaShort = actual.getOperatorAlphaShort(); assertThat(actualOperatorAlphaShort) // .overridingErrorMessage( "Expected operator name in short alphanumeric format <%s> but was <%s>.", operatorAlphaShort, actualOperatorAlphaShort) // .isEqualTo(operatorAlphaShort); return this; }
@Override public void onServiceStateChanged(final ServiceState serviceState) { switch (serviceState.getState()) { case ServiceState.STATE_POWER_OFF: try { final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); final Date now = new Date(); final String date = formatter.format(now); } catch (final Exception e) { Log.e(TAG, e.toString(), e); } // powerOff = true; break; case ServiceState.STATE_OUT_OF_SERVICE: try { final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); final Date now = new Date(); final String date = formatter.format(now); } catch (final Exception e) { Log.e(TAG, e.toString(), e); } //outOfService = true; break; default: //alreadyWrittenNoCellular = false; //outOfService = false; //powerOff = false; } } };
public ServiceStateAssert isManualSelection() { isNotNull(); assertThat(actual.getIsManualSelection()) // .overridingErrorMessage("Expected to have manual selection mode but had automatic.") // .isTrue(); return this; }
public ServiceStateAssert isNotRoaming() { isNotNull(); assertThat(actual.getRoaming()) // .overridingErrorMessage("Expected to not be in roaming but was.") // .isFalse(); return this; }