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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:45:25+00:00 2026-05-24T01:45:25+00:00

Is it possible for an Android app to identify if device is located indoors

  • 0

Is it possible for an Android app to identify if device is located indoors programmatically. My app hangs if it uses GPS indoors. I’m using the following code:

package com.first.Engagia;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class LocationView extends Activity {

    public String userId;
    public String appview_username;
    public String appview_password;
    public String userfirstname;
    public String userlastname;
    public String companyname;
    public String AudienceFirstnameLastname;

    public String LocationString;

    private ProgressDialog mProgressDialog;

    TextView tv;
    boolean fetchedLocationStatus;
    LocationManager locationManager;
    LocationListener locationListener;
    boolean gps_enabled = false;
    boolean network_enabled = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loc);


        //setting passed userId
        Bundle extras = getIntent().getExtras(); 
        if(extras != null){
            this.userId = extras.getString("userId");
            this.appview_username = extras.getString("username");
            this.appview_password = extras.getString("password");

            this.userfirstname = extras.getString("userfirstname");
            this.userlastname = extras.getString("userlastname");
            this.companyname = extras.getString("companyname");

            this.AudienceFirstnameLastname = extras.getString("AudienceFirstnameLastname");

        }

        //tv = (TextView) this.findViewById(R.id.thetext);
        //tv.setText("Android Geo Location Snippet Here.\n\n");
        //tv.setText("");

        showDialog(0);
        LocationView.this.mProgressDialog.setMessage("Getting your location..." );

        // Acquire a reference to the system Location Manager
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        try {
            LocationView.this.gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch(Exception e) {
            Log.e("LocationView", e.toString());
        } 

        try{
            LocationView.this.network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch(Exception e) {
            Log.e("LocationView", e.toString());
        } 


        // Define a listener that responds to location updates
        locationListener = new LocationListener() {

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

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}

        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            if( displayCoordinates(location) == true ) {
                //getAddress( location.getLatitude(), location.getLongitude());
                Log.d("LocationView", "Before Stop Location Updates.");
                stopLocationUpdates();
            }
            }
        };

        if( LocationView.this.gps_enabled == true ){
            // Register the listener with the Location Manager to receive location updates
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        }else if( LocationView.this.network_enabled == true ){
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
        }else if( LocationView.this.gps_enabled == false && LocationView.this.network_enabled == false ){
            LocationUnavailable();
        }

        //so that the program will get the geo location once

    }

    public void stopLocationUpdates(){
        locationManager.removeUpdates(locationListener);
    }

    public void LocationUnavailable(){
        LocationView.this.mProgressDialog.setMessage("Location Unavailable..." );

        if( LocationView.this.mProgressDialog.isShowing() ){
            dismissDialog(0);
        }

        //go back to main_audience.html //3
        Intent nextActivity = new Intent(LocationView.this, AppView.class);

        nextActivity.putExtra("userId", LocationView.this.userId );
        nextActivity.putExtra("username", LocationView.this.appview_username);
        nextActivity.putExtra("password", LocationView.this.appview_password);

        nextActivity.putExtra("userfirstname", LocationView.this.userfirstname );
        nextActivity.putExtra("userlastname", LocationView.this.userlastname );
        nextActivity.putExtra("companyname", LocationView.this.companyname );

        nextActivity.putExtra("AudienceFirstnameLastname", LocationView.this.AudienceFirstnameLastname );

        nextActivity.putExtra("latitude", "Unavailable" );
        nextActivity.putExtra("longitude", "Unavailable" );

        nextActivity.putExtra("origin", "LocationView" );

        finish();
        startActivity(nextActivity);
    }

    public boolean displayCoordinates(Location location){
        //String txtMsg = "Latitude: " + location.getLatitude() + "\nLongitude: " + location.getLongitude();
        //Toast.makeText(getBaseContext(), txtMsg, Toast.LENGTH_SHORT).show();
        LocationView.this.mProgressDialog.setMessage("Location Available..." );

        if( LocationView.this.mProgressDialog.isShowing() ){
            dismissDialog(0);
        }

        //go back to main_audience.html //3
        Intent nextActivity = new Intent(LocationView.this, AppView.class);

        nextActivity.putExtra("userId", LocationView.this.userId );
        nextActivity.putExtra("username", LocationView.this.appview_username);
        nextActivity.putExtra("password", LocationView.this.appview_password);

        nextActivity.putExtra("userfirstname", LocationView.this.userfirstname );
        nextActivity.putExtra("userlastname", LocationView.this.userlastname );
        nextActivity.putExtra("companyname", LocationView.this.companyname );

        nextActivity.putExtra("AudienceFirstnameLastname", LocationView.this.AudienceFirstnameLastname );

        nextActivity.putExtra("latitude", location.getLatitude() );
        nextActivity.putExtra("longitude", location.getLongitude() );
        nextActivity.putExtra("LocationString", LocationView.this.LocationString );

        nextActivity.putExtra("origin", "LocationView" );

        finish();
        startActivity(nextActivity);

        //this.tv.append( txtMsg );
        //Toast.makeText(getBaseContext(), txtMsg, Toast.LENGTH_SHORT).show();

        return true;
    }




    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case 0:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
        }
    }

}
  • 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-05-24T01:45:26+00:00Added an answer on May 24, 2026 at 1:45 am

    Instead of checking whether your device is being used indoor or not, check whether you can receive GPS related details within certain time; if you can not then display some message to user, saying that GPS is not accessible at this point.

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

Sidebar

Related Questions

Is it possible in Android to programmatically send an email using the phone's associated
When using a custom dialog in an Android App how is it then possible
Is it possible to create android app to find map location using Mobile Number.
Using the Android SDK, is it possible to play a video stream using the
Is it possible to use C/C++ code in Android? And how easy is it?
Is this possible in an Android app? I want to make it so that
Is it possible to configure android.app.DatePickerDialog so that it is localized for the European
I was wondering if it was possible to have an android app which is
Possible Duplicate: Why does Android app run in small window on tablet emulator? i
Possible Duplicate: How to detect when an Android app goes to the background and

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.