I have the following classes which are subclasses of AppCompatActivity
and PhoneStateListener
respectively; I want to take 2 values from the second and print them along with the values from the first one.
MainActivity.java
public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.info);
}
public void onSubmit(View v) {
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(new SecondActivity(this),PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
String opname="\nOperator ID:"+" "+tm.getNetworkOperator();
opname=opname+"\nOperator Name:"+" "+tm.getNetworkOperatorName();
int phoneType=tm.getPhoneType();
String ptype="";
switch(phoneType)
{
case TelephonyManager.PHONE_TYPE_CDMA:
ptype="\nPhone Type: CDMA\n";
break;
case TelephonyManager.PHONE_TYPE_GSM:
ptype="\nPhone Type: GSM\n";
break;
case TelephonyManager.PHONE_TYPE_SIP:
ptype="\nPhone Type: SIP\n";
break;
case TelephonyManager.PHONE_TYPE_NONE:
ptype="\nPhone Type: NONE\n";
break;
}
tv.setText(opname+ptype);
}
}
SecondActivity.java
public class SecondActivity extends PhoneStateListener {
Context mcontext;
double value1=0,value2=0;
String error,ss;
public SecondActivity(Context context){
mcontext=context;
}
public void onSignalStrengthsChanged(SignalStrength signalStrength){
super.onSignalStrengthsChanged(signalStrength);
if (signalStrength.isGsm()) {
value1=signalStrength.getGsmBitErrorRate();
error="\nGsmBitErrorRate:"+value1;
value2=signalStrength.getGsmSignalStrength();
ss="\nGsmSignalStrength:"+value2;
}
}
}