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

  • Home
  • SEARCH
  • 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 8225367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:23:35+00:00 2026-06-07T15:23:35+00:00

trying to find the current location of my device.code is here. package com.example.location; import

  • 0

trying to find the current location of my device.code is here.

package com.example.location;

import android.app.Activity;    
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;


public class LocationActivity extends Activity
{

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

  /* Use the LocationManager class to obtain GPS locations */
  LocationManager mlocManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

  LocationListener mlocListener = new MyLocationListener();
  mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
}

/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{

  @Override
  public void onLocationChanged(Location loc)
  {

    loc.getLatitude();
    loc.getLongitude();

    String Text = "My current location is: " +
    "Latitud = " + loc.getLatitude() +
    "Longitud = " + loc.getLongitude();

    Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onProviderDisabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
  }

  @Override
  public void onProviderEnabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
  }

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

  }
}
}

and logcat is

07-15 12:42:49.294: E/AndroidRuntime(3322): FATAL EXCEPTION: main
07-15 12:42:49.294: E/AndroidRuntime(3322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.location/com.example.location.LocationActivity}: java.lang.IllegalArgumentException: provider=network
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.os.Looper.loop(Looper.java:137)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at java.lang.reflect.Method.invoke(Method.java:511)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at dalvik.system.NativeStart.main(Native Method)
07-15 12:42:49.294: E/AndroidRuntime(3322): Caused by: java.lang.IllegalArgumentException: provider=network
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.os.Parcel.readException(Parcel.java:1331)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.os.Parcel.readException(Parcel.java:1281)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.location.LocationManager._requestLocationUpdates(LocationManager.java:589)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.location.LocationManager.requestLocationUpdates(LocationManager.java:453)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at com.example.location.LocationActivity.onCreate(LocationActivity.java:26)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.Activity.performCreate(Activity.java:4465)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-15 12:42:49.294: E/AndroidRuntime(3322):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-15 12:42:49.294: E/AndroidRuntime(3322):     ... 11 more
  • 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-07T15:23:37+00:00Added an answer on June 7, 2026 at 3:23 pm

    Have you tried the same code on Real Device. I think it should work on device, Network provider causes problem on Emulator.

    Edit:- Based on @Felipe comment, Many some devices may not support network provider. Use below method to check if provider is actually enabled or not.

    /*Pass context as well as Provider name, you can get provider name via LocationManager class*/
         public boolean isProviderEnabled(Context ctx, String provider){
            LocationManager manager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
            return manager.isProviderEnabled(provider);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find current location, and this is my code. LocationManager mlocManager
i'm trying to code an app that displays the current device position on a
My app find out current location using GPS . It is working fine in
I am trying to do a simple app that gets the current location in
I'm trying to find a good, current css3 gradient reference, including vendor prefixes. I've
Trying to find an example that has css rollover using sprites & sliding door
I am writing an app that requires the user's current location (lastknownlocation won't be
I was wondering how we would be able to find the current location of
Hey guys, I'm having trouble trying to find the user's longitude and location as
I'm trying to set up a subdomain-to-repository translation in Apache. Example: foobars.domain.com -> /server/svnrepos/foobars

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.