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; }
@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 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; }
@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); } } } };
public void onServiceStateChanged(android.telephony.ServiceState serviceState) { if (serviceState.getState() == ServiceState.STATE_POWER_OFF) { ContentValues mobile = new ContentValues(); mobile.put(Network_Data.TIMESTAMP, System.currentTimeMillis());
//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; }
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()); }