I want to draw a HEAT MAP of MOBILE SIGNAL STRENGTH using Android Studio using signalstrengthlevel, latitudes and longitude

by Asad Sultan   Last Updated December 06, 2018 11:11 AM

I am a beginner to Android and Java. Basically, I want to plot a heat map of the signal strength of my mobile in the vicinity of my university. I have made a Mainctivity.java which tells the current location (latitude, longitude) and a Signal.java activity which tells mobile signal strength. Now I want to use these three variables ("signalstrength, latitude, longitude) to draw a heat map. I went to Google developers site they are using a raw file (A raw file of form police.json, which is a file containing latitude, longitudes of police stations in Victoria), to draw a heat map. Now I want to know:

(1) Firstly, if I want to collect all these three variables, in a raw file, what steps I must follow particularly for my case?

(2) Secondly, if I am to draw a simple heat map at various locations from these three variables, (e.g. {"2", "37.2268", "73.444"}), how should I implement my code in main activity for a new project to draw heat map, with my raw file from step (1) saved in res directory of my project__(A raw file consisting of a lot of rows of three columns {signalstrength, latitude, longitude}).

My MainActivity.java, Signal.java are attached. I searched a lot but did not get a concrete answer. Help will be highly appreciated.

MainActivity.java

public class MainActivity extends AppCompatActivity implements LocationListener {

Button getLocationBtn;
TextView locationText;
Button button;
Button signal;
public static double latit, longit;

LocationManager locationManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_main);

    getLocationBtn = findViewById(R.id.getLocationBtn);
    locationText = findViewById(R.id.LocationText);
    button = findViewById(R.id.Pickpoint);
    signal = findViewById(R.id.signalstrength);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent googlemap = new Intent(MainActivity.this, MapsActivity.class);
            startActivity(googlemap);
        }
    });
    signal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent signalstrength = new Intent(MainActivity.this, Signal.class);
            startActivity(signalstrength);
        }
    });


    if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, 101);

    }


    getLocationBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getLocation();
        }
    });
}

void getLocation() {
    try {
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 5, this);
    } catch (SecurityException e) {
        e.printStackTrace();
    }
}

@Override
public void onLocationChanged(Location location) {
    locationText.setText("Latitude: " + location.getLatitude() + "\n Longitude: " + location.getLongitude());

    try {
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        locationText.setText(locationText.getText() + "\n" + addresses.get(0).getAddressLine(0) + ", " +
                addresses.get(0).getAddressLine(1) + ", " + addresses.get(0).getAddressLine(2));
        latit = location.getLatitude();
        longit = location.getLongitude();

    } catch (Exception e) {

    }

}

@Override
public void onProviderDisabled(String provider) {
    Toast.makeText(MainActivity.this, "Please Enable GPS and Internet", Toast.LENGTH_SHORT).show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}
}

Signal.java

public class Signal extends AppCompatActivity {

private static final String TAG = "MainActivity";

TextView signalTextView_level;
TextView signalTextView_dbm;
TelephonyManager telephonyManager;
myPhoneStateListener psListener;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signal);
    signalTextView_level = findViewById(R.id.signalTextView_level);
    signalTextView_dbm = findViewById(R.id.signalTextView_dbm);
    psListener = new myPhoneStateListener();
    telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(psListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

}
public class myPhoneStateListener extends PhoneStateListener {
    public int signalStrengthValue_level;
    public  int signalStrengthValue_dbm;

    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);
        signalStrengthValue_level = signalStrength.getLevel();
        signalStrengthValue_dbm = signalStrength.getGsmSignalStrength();
        if (signalStrength.isGsm()) {
            if (signalStrength.getGsmSignalStrength() != 99)
                signalStrengthValue_dbm = signalStrength.getGsmSignalStrength() * 2 - 113;
            else
                signalStrengthValue_dbm = signalStrength.getGsmSignalStrength();
        }
        /*else {
            signalStrengthValue = signalStrength.getLevel();
        }*/
        signalTextView_level.setText("Signal Strength level: " + signalStrengthValue_level);
        signalTextView_dbm.setText("Signal Strength in dbm: "+signalStrengthValue_dbm);

    }
}

}


Related Questions


Updated September 03, 2016 08:04 AM

Updated March 19, 2017 06:11 AM

Updated April 02, 2018 18:11 PM

Updated February 21, 2017 19:11 PM