Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class HomeActivity extends Activity implements LocationListener{ public static Context mContext; private double latitude, longitude; public LocationManager mLocManager; @Override protected void onCreate(Bundle savedInstanceState) { mContext=this; super.onCreate(savedInstanceState); setContentView(R.layout.homelayout); mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); mLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); locationUpdate(); ((Button) this.findViewById(R.id.ButtonHome)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { startActivity(new Intent(HomeActivity.this, DefaultDisplay.class)); } }); ((Button) this.findViewById(R.id.ButtonProfile)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if (GUIStatics.boolLoginStatus) { startActivity(new Intent(HomeActivity.this, MyProfile.class)); } else { Intent intent=new Intent(HomeActivity.this, Login.class); intent.putExtra("moveTo","MyProfile"); startActivity(intent); } } }); ((Button) this.findViewById(R.id.ButtonNotifications)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if (GUIStatics.boolLoginStatus) { startActivity(new Intent(HomeActivity.this, ShowAllNotificationActiviry.class)); } else { Intent intent=new Intent(HomeActivity.this, Login.class); intent.putExtra("moveTo","ShowAllNotificationActiviry"); startActivity(intent); } } }); ((Button) this.findViewById(R.id.ButtonFavorites)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if (GUIStatics.boolLoginStatus) { startActivity(new Intent(HomeActivity.this, FavoritesActivity.class)); } else { Intent intent=new Intent(HomeActivity.this, Login.class); intent.putExtra("moveTo","FavoritesActivity"); startActivity(intent); } } }); ((Button) this.findViewById(R.id.ButtonMore)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { startActivity(new Intent(HomeActivity.this, MoreListActivity.class)); } }); } public void locationUpdate() { CellLocation.requestLocationUpdate(); } public void getAddress(double lat, double lng) { Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault()); try { List&lt;Address&gt; addresses = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); String add = obj.getAddressLine(0); GUIStatics.currentAddress = obj.getSubAdminArea() + "," + obj.getAdminArea(); GUIStatics.latitude = obj.getLatitude(); GUIStatics.longitude = obj.getLongitude(); GUIStatics.currentCity= obj.getSubAdminArea(); GUIStatics.currentState= obj.getAdminArea(); add = add + "\n" + obj.getCountryName(); add = add + "\n" + obj.getCountryCode(); add = add + "\n" + obj.getAdminArea(); add = add + "\n" + obj.getPostalCode(); add = add + "\n" + obj.getSubAdminArea(); add = add + "\n" + obj.getLocality(); add = add + "\n" + obj.getSubThoroughfare(); Log.v("IGA", "Address" + add); // Toast.makeText(this, "Address=&gt;" + add, // Toast.LENGTH_SHORT).show(); // TennisAppActivity.showDialog(add); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); } } public void onLocationChanged(Location location) { latitude = location.getLatitude(); longitude = location.getLongitude(); GUIStatics.latitude=location.getLatitude(); GUIStatics.longitude= location.getLongitude(); Log.v("Test", "IGA" + "Lat" + latitude + " Lng" + longitude); //mLocManager.r getAddress(latitude, longitude); if(location!=null) { mLocManager.removeUpdates(this); } // Toast.makeText(this, "Lat" + latitude + " Lng" + longitude, // Toast.LENGTH_SHORT).show(); } public void onProviderDisabled(String arg0) { // TODO Auto-generated method stub Toast.makeText(HomeActivity.this, "Gps Disabled", Toast.LENGTH_SHORT).show(); Intent intent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } public void onProviderEnabled(String arg0) { // TODO Auto-generated method stub } public void onStatusChanged(String arg0, int arg1, Bundle arg2) { if(arg1 == LocationProvider.TEMPORARILY_UNAVAILABLE) { Toast.makeText(HomeActivity.this, "LocationProvider.TEMPORARILY_UNAVAILABLE", Toast.LENGTH_SHORT).show(); } else if(arg1== LocationProvider.OUT_OF_SERVICE) { Toast.makeText(HomeActivity.this, "LocationProvider.OUT_OF_SERVICE", Toast.LENGTH_SHORT).show(); } } </code></pre> <p>} This is the my code i am using this for getting user current location. Read it carefully the check what the mistake you have done in your code. and also check all the permission in mainfest file related to gps.</p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_GPS" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; </code></pre> <p>I hope this is help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload