Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:35:52+00:00 2026-06-12T21:35:52+00:00

public class ReplyWithAddressService extends Service{ public static final String GOOGLE_GEOCODER = http://maps.googleapis.com/maps/api/geocode/json?latlng=; private String

  • 0
public class ReplyWithAddressService extends Service{

public static final String GOOGLE_GEOCODER = "http://maps.googleapis.com/maps/api/geocode/json?latlng=";
private String msgRecipient;
private LocationManager manager;
private MyLocationListener listener;
private static double latitude = -1;
private static double longitude = -1;
private String provider;
private String smsMessageString = "";
public static String filenames = "AntiTheft";
SharedPreferences pref;
String email;

@Override
public IBinder onBind(Intent intent){
    return null;
}

@Override
public void onCreate(){
    super.onCreate();
    Log.d(this.getClass().getName(), "Service created");
    pref = getSharedPreferences(filenames, 0);
    manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    listener = new MyLocationListener();

    if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        provider = LocationManager.GPS_PROVIDER;
    }
    else if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
        provider = LocationManager.NETWORK_PROVIDER;
    }

    manager.requestLocationUpdates(provider, 0, 0, listener);
}

@Override
public void onStart(Intent intent, int startId){
    super.onStart(intent, startId);
    Log.d(this.getClass().getName(), "Service started");
    //Extract Intent Data
    msgRecipient = intent.getStringExtra("number");
    String emailAddress = pref.getString("keyemail", "");
    String contact1 = pref.getString("contact1", "");
    String contact2 = pref.getString("contact2", "");
    Log.d(this.getClass().getName(), "Number: " + msgRecipient);
    ConnectivityManager cManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cManager.getActiveNetworkInfo();

    //Get Location
    if (ReplyWithAddressService.latitude == -1 || ReplyWithAddressService.longitude == -1){
        Location location = manager.getLastKnownLocation(provider);

        if (location != null){
            ReplyWithAddressService.latitude = location.getLatitude();
            ReplyWithAddressService.longitude = location.getLongitude();

            if (info != null){

                if (info.isConnected()){
                    String address = ReplyWithAddressService.getAddressFromGPSData(ReplyWithAddressService.latitude, ReplyWithAddressService.longitude);
                    smsMessageString += "Current Location: " + address + "."; 
                }
            }

            smsMessageString += "Link: http://maps.google.com/maps?q=" + ReplyWithAddressService.latitude + "+" + ReplyWithAddressService.longitude;
            Log.d("Message", smsMessageString);
        }
        else{
            smsMessageString = "Location Data is Not Available";
        }
    }

    SmsManager sManager = SmsManager.getDefault();
    String number = msgRecipient;
    String contactNo1 = contact1;
    String contactNo2 = contact2;
    email = emailAddress; 

    //Send SMS message
    sManager.sendTextMessage(number, null, smsMessageString, null, null);
    sManager.sendTextMessage(contactNo1, null, smsMessageString, null, null);
    sManager.sendTextMessage(contactNo2, null, smsMessageString, null, null);

    try{
        sendMail();
    } catch(MessagingException e){
        e.printStackTrace();
    }

    stopSelf(startId);
}

I am developing a location tracker mobile apps and once the lost mobile phone retrieves the location, it will send the current location to a predefined email address and mobile phone numbers. It has no problem if my phone is connected to Wi-Fi, but when I turn off the Wi-Fi, I am not able to receive the location information via my email, I just want to know how can I do to check is there any Wi-Fi connected in my mobile, if yes, then Wi-Fi is preferred and if not, enable the mobile network automatically in order to send out the email message. My purpose is to make sure the email can be sent out under any condition (no matter Wi-Fi present or not)… Hope someone can help me, thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:35:53+00:00Added an answer on June 12, 2026 at 9:35 pm

    You can register a BroadcastReceiver to be notified when a WiFi connection is established or has been changed.

    Register the BroadcastReceiver:

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    registerReceiver(broadcastReceiver, intentFilter);
    

    And then in that BroadcastReceiver you can use something like:

      @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
            if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                //wifi is connected. You can do stuff here.
            } else {
                // wifi connection is gone.
            }
        }
    

    Docs for BroadcastReceiver:
    http://developer.android.com/reference/android/content/BroadcastReceiver.html

    Docs for WifiManager:
    http://developer.android.com/reference/android/net/wifi/WifiManager.html

    You need to check if device is already connected to wifi before using the above code since the above code will only notify you when the connection state is changed. It has be connected in the first place. To check that, you can use:

    WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        if (wifiInfo != null) {
            //connection is established
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class Base{ protected String str; public static final Base ERROR = new Base(error);
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class DBAdapter { public static final String COLUMN_ID = ID; public static final
public class SaveData extends Activity implements OnClickListener { private DataManipulator dh; static final int
public class SequenceControlNumber extends SequenceGenerator { private static final Logger log = LoggerFactory.getLogger(SequenceGenerator.class); @Override
public class FBPost extends Service{ private Bundle params = new Bundle(); private String userID=;
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.