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 8671973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:05:15+00:00 2026-06-12T19:05:15+00:00

In an android app, I have written code to get geo data through GPS

  • 0

In an android app, I have written code to get geo data through GPS or Network, which one is enable get the data through that. Here is my code,

public boolean getLocation(Context context, LocationResult result)
{
    boolean gps_enabled=false;
    LocationManager lm;
    boolean network_enabled=false; 
    this.context = context;
    locationResult=result;
    Toast.makeText( context,"getLocation()",Toast.LENGTH_SHORT).show();
    if(lm == null)
        lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    try
    {
        gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }
    catch(Exception ex){}

    try
    {
        network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    }
    catch(Exception ex){}


    if(!gps_enabled && !network_enabled)
    {
        Toast.makeText(context, "GPS & Network disabled", Toast.LENGTH_SHORT).show();
        return false;
    }
}

Using LocationManager check whether GPS & NetWork is on or not.

If GPS is in ON, in boolean value gps_enabled assigned “true”.

But in network, I have activated 2G Internet access in HTC desire android device, and Switched ON in Mobile network.

The boolean variable network_enabled assigned to “false” even network in On state.

Are we want to change in settings anything in device? or any mistake in my code?

  • 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-12T19:05:17+00:00Added an answer on June 12, 2026 at 7:05 pm

    That depends on availability:

    Location net_loc=null, gps_loc=null;
    if(gps_enabled)
    gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(network_enabled)
    net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    

    NETWORK_PROVIDER: Name of the network location provider. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.

    GPS_PROVIDER : Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.

    See this link: http://developer.android.com/reference/android/location/LocationManager.html#getBestProvider%28android.location.Criteria,%20boolean%29

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small android app that grabs some data and displays it
I have written following code to get location name package demo.gps.locname; import java.io.IOException; import
I have written an android app which listens to the phone signal strength using
I have written an Android application that uses SQLite database which is saved in
I have an app written for Android 2.2 (API 8) that depends on some
I am developing an Android app. I have written my own code for back
I have written an app which fetches data from a server. I am not
In my android app I have fragments, and one of them is very heavy
I started developing an android app that have to interact with MMS attachements, in
I have android app . i should pass the data from android to web

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.