0

I don't want to use service which is continuously running in background ! Actually in my project user will send SMS command from any smartphone to his/her misplaced smartphone.My app will detect that particular "SMS command" and in return it will send the current location of misplaced mobile. can it be done through intent service ? I m damn confused ... Its single time operation how to perform it efficiently ... ?

CodeChimp
  • 4,745
  • 6
  • 45
  • 61
Qaiser Hussain
  • 170
  • 1
  • 11

1 Answers1

0

by using NETWORK_PROVIDER getting geolocation

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

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

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

and add this permission in manifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Venki WAR
  • 1,997
  • 4
  • 25
  • 38
  • should I copy this code in intent service then call this intent service in broadcast receiver ? – Qaiser Hussain May 30 '18 at 11:38
  • I think your app must run in background for finding SMS Command .If command found you simply send geolocation that number – Venki WAR May 30 '18 at 11:43
  • I have done that job "finding SMS Command" I have used incoming SMS broadcast receiver for it blah blah ... do I just need to call ur code from broadcast receiver that's it ? – Qaiser Hussain May 30 '18 at 11:49