sorry for my bad english.
I want to ask about android telephony : CellSignalStrength
I have code like below to display signal strength information on android..
public class MainActivity extends AppCompatActivity {
private TextView textView2;
public String gsmStrength;
#SuppressLint("MissingPermission")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView2 = (TextView) findViewById(R.id.textView2);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
try {
for (CellInfo info : tm.getAllCellInfo()) {
if (info instanceof CellInfoGsm) {
CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
// do what you need
gsmStrength = String.valueOf(gsm.getDbm());
} else if (info instanceof CellInfoCdma) {
CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
gsmStrength = String.valueOf(cdma.getDbm());
} else if (info instanceof CellInfoLte) {
CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
gsmStrength = String.valueOf(lte.getDbm());
} else {
gsmStrength = String.valueOf("UNknown");
}
}
}catch (Exception e){
Log.d("SignalStrength", "+++++++++++++++++++++++++++++++ null array spot 3: " + e);
}
textView2.setText(gsmStrength.toString());
when I run it shows the result is -93
so what I want is the result in the form of a string with what information it is:
SIGNAL_STRENGTH_GOOD
SIGNAL_STRENGTH_GREAT
SIGNAL_STRENGTH_MODERATE
SIGNAL_STRENGTH_POOR
like the picture below:
not the number -93 earlier
Instead of using getDbm() which return the "signal strength as dBm" you should use getLevel()
Retrieve an abstract level value for the overall signal quality.
Returns int value between SIGNAL_STRENGTH_NONE_OR_UNKNOWN and SIGNAL_STRENGTH_GREAT inclusive
https://developer.android.com/reference/android/telephony/CellSignalStrengthGsm#getLevel()
So you get one of the int values from CellSignalStrength:
CellSignalStrength.SIGNAL_STRENGTH_GOOD
CellSignalStrength.SIGNAL_STRENGTH_GREAT
CellSignalStrength.SIGNAL_STRENGTH_MODERATE
CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN
CellSignalStrength.SIGNAL_STRENGTH_POOR
If you still want to get a string instead of the int you can use
public static String getLevelString(int level) {
switch(level) {
case CellSignalStrength.SIGNAL_STRENGTH_GOOD:
return "SIGNAL_STRENGTH_GOOD";
case CellSignalStrength.SIGNAL_STRENGTH_GREAT:
return "SIGNAL_STRENGTH_GREAT";
case CellSignalStrength.SIGNAL_STRENGTH_MODERATE:
return "SIGNAL_STRENGTH_MODERATE";
case CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN:
return "SIGNAL_STRENGTH_NONE_OR_UNKNOWN";
case CellSignalStrength.SIGNAL_STRENGTH_POOR:
return "SIGNAL_STRENGTH_POOR";
default:
throw new RuntimeException("Unsupported level " + level);
}
}
Related
I am making the calculator app. It shows double at the result even when I don't use double.
Example) 1+1 = 2.0
But I want like 1+1= 2
Of course, I want to keep double when there is double like 1.2+1.3= 2.5
How should I have to edit?
I tried to edit like this, but there is an error.
public void equalsOnClick(View view)
{
Integer result = null;
ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino");
try {
result = (int)engine.eval(workings);
} catch (ScriptException e)
{
Toast.makeText(this, "Invalid Input", Toast.LENGTH_SHORT).show();
}
if(result != null)
resultsTV.setText(String.valueOf(result.intValue()));
}
MainActivity
public class MainActivity extends AppCompatActivity {
TextView workingsTV;
TextView resultsTV;
String workings = "";
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initTextView();
}
private void initTextView()
{
workingsTV = (TextView)findViewById(R.id.workingsTextView);
resultsTV = (TextView)findViewById(R.id.resultTextView);
}
private void setWorkings(String givenValue)
{
workings = workings + givenValue;
workingsTV.setText(workings);
}
public void equalsOnClick(View view)
{
Double result = null;
ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino");
try {
result = (double)engine.eval(workings);
} catch (ScriptException e)
{
Toast.makeText(this, "Invalid Input", Toast.LENGTH_SHORT).show();
}
if(result != null)
resultsTV.setText(String.valueOf(result.doubleValue()));
}
public void clearOnClick(View view)
{
workingsTV.setText("");
workings = "";
resultsTV.setText("");
leftBracket = true;
}
}
It is happening because you have declared result of type, Double. Therefore, until you cast it's doubleValue() into an int and set the same to resultsTV, its double value will be set there.
Change your method definition as follows:
public void equalsOnClick(View view) {
Double result = null;
ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino");
try {
result = (Double)engine.eval(workings);
if(result != null) {
int intVal = (int)result.doubleValue();
if(result == intVal) {// Check if it's value is equal to its integer part
resultsTV.setText(String.valueOf(intVal));
} else {
resultsTV.setText(String.valueOf(result));
}
}
} catch (ScriptException e) {
Toast.makeText(this, "Invalid Input", Toast.LENGTH_SHORT).show();
}
}
Note that I have also moved resultsTV.setText inside the try-catch block so that it gets executed only when result = (Double)engine.eval(workings) does not throw an exception.
Use the modulo operator to check whether a double is an Integer
(result %1 ==0)
or Math.floor then check whether result changed or not.
If it is, you can use Integer.valueOf(result)
Integer has a built in toString method by the way.
Nothing to do.
Just check the string on whether it ended with ".0"
If so, just replace the string like this: replace(".0","");
In the else condition, insert the string as you input like now.
i have to remove a object from my List within my BaseCardAdapter. This BaseCardAdapter is used for my SwipeCardView. I try to remove an object after pressing a button. After that i need to notify the adapter that one object is removed. Unfortunately i receive this error:
java.lang.IllegalMonitorStateException: object not locked by thread before notify()
Here is my Code:
public class FeedAdapter extends BaseCardAdapter {
private ArrayList<EventObject> events;
private Activity activity;
private TextView property1, property2, property3, usernameage;
private ImageView userthumb;
public FeedAdapter(ArrayList<EventObject> events, Activity activity) {
this.events = events;
this.activity = activity;
}
#Override
public int getCount() {
return events.size();
}
#Override
public int getCardLayoutId() {
return R.layout.model_idea_feed;
}
#Override
public void onBindData(final int position, View cardview) {
if (events.size() == 0 || events == null){
return;
}
ImageView thumb = cardview.findViewById(R.id.feed_thumb_model);
userthumb = cardview.findViewById(R.id.feed_profile_thumb);
final TextView eventname = cardview.findViewById(R.id.feed_name_model);
usernameage = cardview.findViewById(R.id.feed_username_model);
TextView date = cardview.findViewById(R.id.feed_date_model);
TextView additional = cardview.findViewById(R.id.feed_additional_model);
TextView address = cardview.findViewById(R.id.feed_adress_model);
property1 = cardview.findViewById(R.id.feed_property1_model);
property2 = cardview.findViewById(R.id.feed_property2_model);
property3 = cardview.findViewById(R.id.feed_property3_model);
ImageButton save = cardview.findViewById(R.id.feed_savebtn_model);
ImageButton accept = cardview.findViewById(R.id.feed_accept_model);
switch(Integer.parseInt(events.get(position).getPosition())) {
case 0:
thumb.setBackgroundResource(R.drawable.berlin0);
break;
case 1:
thumb.setBackgroundResource(R.drawable.berlin1);
break;
case 2:
thumb.setBackgroundResource(R.drawable.berlin2);
break;
default:
thumb.setBackgroundResource(R.drawable.berlin2);
break;
}
eventname.setText(events.get(position).getName());
date.setText(events.get(position).getDate());
additional.setText(events.get(position).getInfos());
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(activity, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(Double.parseDouble(events.get(position).getLat()),Double.parseDouble(events.get(position).getLng()), 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
String adderess = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
address.setText(adderess);
} catch (IOException e) {
e.printStackTrace();
}
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
events.remove(events.get(position));
//Here Appears the error:
events.notify();
}
});
}
}
notify() is something completely unrelated to lists and Adapters.
What you want is notifyDataSetChanged(), called on the Adapter itself, not the data list.
Replace:
events.notify();
With:
notifyDataSetChanged();
Or:
notifyItemRemoved(position);
I am making an app which consists of an activity and a service. By pressing a button the service is started, it collects data in the background from a sensor and classifies it and outputs a string. I want to display the string in a textView. Right now I can see in the log that the variable is updated 2 times every second, but when I try and update the textView from the service class nothing is happening unless I press the button, whenever I press the button, the string is displayed in the textView.
What is the easiest solution here? I tried to make the textView static and it still can't update it. Can you make it so that the view is updated automatically every second? Can I add a listener somehow? Since I am not very experienced I would like an easy solution that does not have to be a "good" one.
Here is my code
Activity:
public class CollectorActivity extends Activity {
private enum State {
IDLE, COLLECTING, TRAINING, CLASSIFYING
};
private final String[] mLabels = { Globals.CLASS_LABEL_STANDING,
Globals.CLASS_LABEL_WALKING, Globals.CLASS_LABEL_RUNNING,
Globals.CLASS_LABEL_OTHER };
private RadioGroup radioGroup;
private final RadioButton[] radioBtns = new RadioButton[4];
private Intent mServiceIntent;
private File mFeatureFile;
public static TextView mCurrentLabel;
private State mState;
private Button btnDelete;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
radioGroup = (RadioGroup) findViewById(R.id.radioGroupLabels);
radioBtns[0] = (RadioButton) findViewById(R.id.radioStanding);
radioBtns[1] = (RadioButton) findViewById(R.id.radioWalking);
radioBtns[2] = (RadioButton) findViewById(R.id.radioRunning);
radioBtns[3] = (RadioButton) findViewById(R.id.radioOther);
btnDelete = (Button) findViewById(R.id.btnDeleteData);
mCurrentLabel = (TextView) findViewById(R.id.textView);
mState = State.IDLE;
mFeatureFile = new File(getExternalFilesDir(null),
Globals.FEATURE_FILE_NAME);
mServiceIntent = new Intent(this, SensorsService.class);
}
public void onCollectClicked(View view) {
if (mState == State.IDLE) {
mState = State.COLLECTING;
((Button) view).setText(R.string.ui_collector_button_stop_title);
btnDelete.setEnabled(false);
radioBtns[0].setEnabled(false);
radioBtns[1].setEnabled(false);
radioBtns[2].setEnabled(false);
radioBtns[3].setEnabled(false);
int acvitivtyId = radioGroup.indexOfChild(findViewById(radioGroup
.getCheckedRadioButtonId()));
String label = mLabels[acvitivtyId];
Bundle extras = new Bundle();
extras.putString(Globals.CLASS_LABEL_KEY, label);
mServiceIntent.putExtras(extras);
startService(mServiceIntent);
} else if (mState == State.COLLECTING) {
mState = State.IDLE;
((Button) view).setText(R.string.ui_collector_button_start_title);
btnDelete.setEnabled(true);
radioBtns[0].setEnabled(true);
radioBtns[1].setEnabled(true);
radioBtns[2].setEnabled(true);
radioBtns[3].setEnabled(true);
stopService(mServiceIntent);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll();
}
}
public void onDeleteDataClicked(View view) {
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
if (mFeatureFile.exists()) {
mFeatureFile.delete();
}
Toast.makeText(getApplicationContext(),
R.string.ui_collector_toast_file_deleted,
Toast.LENGTH_SHORT).show();
}
}
#Override
public void onBackPressed() {
if (mState == State.TRAINING) {
return;
} else if (mState == State.COLLECTING || mState == State.CLASSIFYING) {
stopService(mServiceIntent);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.cancel(Globals.NOTIFICATION_ID);
}
super.onBackPressed();
}
#Override
public void onDestroy() {
// Stop the service and the notification.
// Need to check whether the mSensorService is null or not.
if (mState == State.TRAINING) {
return;
} else if (mState == State.COLLECTING || mState == State.CLASSIFYING) {
stopService(mServiceIntent);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.cancelAll();
}
finish();
super.onDestroy();
}
And this is the "doInBackground" method in my service class. The line "CollectorActivity.mCurrentLabel.setText(classification);" is the problem. I want this to update the textView continously.
public class OnSensorChangedTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... arg0) {
Instance inst = new DenseInstance(mFeatLen);
inst.setDataset(mDataset);
Instance inst2 = new DenseInstance(65);
int blockSize = 0;
FFT fft = new FFT(Globals.ACCELEROMETER_BLOCK_CAPACITY);
double[] accBlock = new double[Globals.ACCELEROMETER_BLOCK_CAPACITY];
double[] re = accBlock;
double[] im = new double[Globals.ACCELEROMETER_BLOCK_CAPACITY];
double max = Double.MIN_VALUE;
while (true) {
try {
// need to check if the AsyncTask is cancelled or not in the while loop
if (isCancelled () == true)
{
return null;
}
// Dumping buffer
accBlock[blockSize++] = mAccBuffer.take().doubleValue();
if (blockSize == Globals.ACCELEROMETER_BLOCK_CAPACITY) {
blockSize = 0;
testList = new ArrayList<Double>();
// time = System.currentTimeMillis();
max = .0;
for (double val : accBlock) {
if (max < val) {
max = val;
}
}
fft.fft(re, im);
for (int i = 0; i < re.length; i++) {
double mag = Math.sqrt(re[i] * re[i] + im[i]
* im[i]);
inst.setValue(i, mag);
testList.add(i,mag);
im[i] = .0; // Clear the field
}
// Append max after frequency component
inst.setValue(Globals.ACCELEROMETER_BLOCK_CAPACITY, max);
inst2.setValue(Globals.ACCELEROMETER_BLOCK_CAPACITY, max);
testList.add(max);
classificationIndex = WekaClassifier.classify(testList.toArray());
classification = testLabel.get((int) classificationIndex);
CollectorActivity.mCurrentLabel.setText(classification);
inst.setValue(mClassAttribute, mLabel);
mDataset.add(inst);
Log.i("new instance", mDataset.size() + "");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
In doInBackground(Void... arg0) change CollectorActivity.mCurrentLabel.setText(classification); to publishProgress(classification); then change second argument from Void to String: public class OnSensorChangedTask extends AsyncTask<Void, Srting, Void> and add onProgressUpdate().
Finally your code should looks like:
public class OnSensorChangedTask extends AsyncTask<Void, Srting, Void> {
#Override
protected Void doInBackground(Void... arg0) {
//...
publishProgress(classification);
//...
}
#Override
protected Void onProgressUpdate(String... classification) {
CollectorActivity.mCurrentLabel.setText(classification[0]);
}
I get a phone number at the time of the ringing state, but sometimes, it is set to null at the time of the off hook state. I can't catch the moment where it goes to null.
So, when a call comes (incoming call) it goes to RINGING STATE and the number is set to callno variable. After that when I pick up the call it goes to OFFHOOK STATE and I got null in callno therefore it gives me a NullPointerException.
How do I prevent this situation?
public class CallStateReceiver extends BroadcastReceiver {
private static boolean noCallListenerYet = true;
TelephonyManager telephonyManager;
static MyPhoneStateListener phoneListener;
private static Context context1;
Context context;
private int prevState;
String userId;
String incoming_number = null;
Bundle bundle;
String state;
private static String callno = null;
static SharedPreferences pref;
static int cidvalue;
/*Added to resolve the below bug:
* Bug: At the time of call comes on poped up note and
* below note was not send and new userid not
* replace with older userid.
*/
private static boolean isOnReceive = false;
public static String getCallno() {
return callno;
}
#Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
isOnReceive = true;
if( CallTrackerModel.isRecording() ){
}else{
CallTrackerModel.setCallId("");
try{
if (intent.getAction()
.equals("android.intent.action.NEW_OUTGOING_CALL")) {
if ((bundle = intent.getExtras()) != null) {
callno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
callno = callno.replaceAll(" ", "");
}
}
}
catch(Exception e){
}
try{
if (noCallListenerYet) {
telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (phoneListener == null) {
phoneListener = new MyPhoneStateListener(context);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
noCallListenerYet = false;
}
}catch(Exception e){
isOnReceive = false;
}
context1 = context;
}
}
public static int returncid() {
int cid;
pref = context1.getSharedPreferences("Myprefer", 0);
SharedPreferences.Editor editor = pref.edit();
cid = pref.getInt("currentcid", 0);
if (cid == 0) {
cid = cid + 1;
}
editor.putInt("currentcid", cid);
editor.commit();
pref = context1.getSharedPreferences("Myprefer", 0);
cidvalue = pref.getInt("currentcid", 0);
return cidvalue;
}
private class MyPhoneStateListener extends PhoneStateListener {
Context context;
MyPhoneStateListener(Context c) {
super();
context = c;
}
/**
* Listen call state changes.
*/
public void onCallStateChanged(int state, String incomingNumber) {
CallTrackerModel ctm = new CallTrackerModel(context1);
switch (state) {
// Incoming/Outgoing call over.
case TelephonyManager.CALL_STATE_IDLE:
if (CallTrackerModel.returnRecordStarted()) {
ctm.stopRecording();
userId = RetrieveUserId.getUserId();
}
//For Received calls.
if (prevState == TelephonyManager.CALL_STATE_OFFHOOK) {
try{
cidvalue = pref.getInt("currentcid", 0);
++cidvalue;
pref = context1.getSharedPreferences("Myprefer", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("currentcid", cidvalue);
editor.commit();
prevState = state;
// Start note activity.
Intent i = new Intent(context1, NoteActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (userId == null) {
userId = "##";
}
i.putExtra("userId", userId);
i.putExtra("isSend", false);
i.putExtra("incomingNumber", incoming_number);
context1.startActivity(i);
i = null;
}catch(Exception ex){
}
}
//For missed calls.
if(prevState==TelephonyManager.CALL_STATE_RINGING){
prevState=state;
}
break;
//If the caller or receiver picks up the phone
case TelephonyManager.CALL_STATE_OFFHOOK:
try{
if( CallTrackerModel.isRecording() ){
break;
}
if( NoteActivity.getIsStart() ){
NoteActivity.setStop(true);
}
prevState = state;
if (callno.length() == 13) {
incoming_number = callno.substring(3);
} else if (callno.length() == 11) {
incoming_number = callno.substring(1);
} else {
incoming_number = callno;
}
}catch(Exception ex){
isOnReceive = false;
}
try{
if( NoteActivity.getIsStop() ){
if(NoteActivity.getLater()){
NoteActivity.setLater(false);
NoteActivity.setStop(false);
}else{
NoteActivity.later();
}
}
}catch(Exception e){
isOnReceive = false;
}
try{
Intent i = new Intent(context1, RetrieveUserId.class);
i.putExtra("incoming number", incoming_number);
context1.startService(i);
// start recording
ctm.startRecording();
}catch(Exception e){
isOnReceive = false;
}
break;
case TelephonyManager.CALL_STATE_RINGING:
if( CallTrackerModel.isRecording() ){
}else{
prevState = state;
callno = incomingNumber;
callno = callno.replaceAll(" ", "");
}
break;
}
}
}
}
Your Broadast Recevier gets fired each time the Phone State Changes.
What this does is it sets the incoming_no to null after Ringing, each time the state changes.
First the phone Rings. At that moment you are able to get the number. When the Phone number changes state to IDLE or OFF_HOOK, your number gets set to null again, since the BR fires all over again.
String incoming_number = null; is what is setting your number to null. This is the code that is messing it up. Turn it into:
MainActivity:
String incoming_number;
BroadcastReceiver
MainActivity.incomingnumber = XXX-XXX-XXXX ;
//when done with the number clean it
MainActivity.incomingnumber = null;
or you could just delete your call recording app. The call recording apps cause this problem also.
I am trying to show the current signal strength and current cell ID and Lac in my application for 3g network. Since it has to be compatible for API-8, I am using SignalStrength class from android.telephony. When I click a button, for now I want it to show the CID, Lac and signal strength of current cell. I am getting the CID and lac but the signal strength is always showing 0. The code is given below:
public void onClick(View v) {
switch (v.getId()) {
case R.id.bShowCell:
GsmCellLocation location;
String cellID = "";
String lac = "";
Context context = (Context) getApplicationContext();
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
location = (GsmCellLocation) tm.getCellLocation();
cellID = String.valueOf(location.getCid());
lac = String.valueOf(location.getLac());
CurCell.setText(cellID);
CellLac.setText(lac);
CurStrgth.setText(getRSSI());
}
}
public String getRSSI() {
MyListener = new MyPhoneStateListener();
Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
String strength = MyListener.getStrength();
return strength;
}
class MyPhoneStateListener extends PhoneStateListener {
public int singalStrengths;
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
int asu = signalStrength.getGsmSignalStrength();
singalStrengths = -113 + 2 * asu;
}
public String getStrength() {
return String.valueOf(singalStrengths);
}
}
I have checked many examples online and I think my code is okay. But when I checked it in debug mode, I see that when I click the button, the program never goes in onSignalStrengthsChanged. Is there anything I am missing?
Well, this is how I tried later and it worked fine. I had to make the CurStrgth.setText()independent from the Button and inside the PhoneStateListener and called the listener from OnCreate() method. And it works fine, updates the CurStrgth TextView whenever it gets a change in the signal strength. My code is given below:
public class MainActivity extends Activity implements OnClickListener {
TextView CurStrgth;
MyPhoneStateListener MyListener;
TelephonyManager Tel;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CurStrgth = (TextView) findViewById(R.id.tvCurCellStrength);
MyListener = new MyPhoneStateListener();
Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
#Override
protected void onPause() {
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
}
#Override
protected void onResume() {
super.onResume();
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
private class MyPhoneStateListener extends PhoneStateListener {
String gsmStrength = "";
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
gsmStrength = String
.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113);
CurStrgth.setText(MyListener.getStrength() + "dBm");
}
public String getStrength() {
return gsmStrength;
}
}
}
Now, I checked just calling the
CurStrgth.setText(MyListener.getStrength() + "dBm");
inside the OnClick() method for a button and it shows only the value once but If I press the button later It never updates the Strength and keeps showing the initial value.