Fused Location not Working Android - android

I am trying to write an app that gets the current location and displays the latitude and longitude realtime. However, when I run this app, the gps doesn't seem to search for a location and try to get a fix. I don't know why this is happening. Have I missed something out? If I open the maps app the location immediately gets a fix. But in my app the gps is not searching for one, or atleast, in the notification bar, it is not showing anything like 'searching for gps' which is usually shown by the maps app.
My main activity:
package com.example.android.location1;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, LocationListener{
private final String LOG_TAG = "TestApp";
private TextView txtOutput;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private static final int REQUEST_PERMISSION = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).build();
txtOutput = (TextView) findViewById(R.id.txtOutput);
}
#Override
protected void onStart(){
super.onStart();
mGoogleApiClient.connect();
}
#Override
protected void onStop(){
mGoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onConnected(Bundle bundle){
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000).setMaxWaitTime(2000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION);
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
#Override
public void onConnectionSuspended(int i){
Log.i(LOG_TAG, "GoogleApiClient connection has been suspended.");
}
#Override
public void onLocationChanged(Location location){
Log.i(LOG_TAG, location.toString());
txtOutput.setText(String.valueOf(location.getLatitude()) + ", " + String.valueOf(location.getLongitude()));
}
}
My manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.location1">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.location.gps"/>
<uses-feature android:name="android.hardware.location.network"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have tested this on android 6 and 7. Doesn't work in either of them. Any help would be appreciated.

Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Then register the locationupdates and attach it to the listener that you already have implementet
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3, 1, locationListener);
Read about the requestlocationsUpdates method on how often etc you what your location.
https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates

Related

MapsApp that calculates distance between 2 points, Android

I would like to create an app that can calculate distance between 2 location, the first is find with GPS,while the second is set by me. The app doesn't open, and the error is in the
line 61: distance = location.distanceTo(locationSede);
Help me!
package com.example.prova.mapapplicationprove;
import android.Manifest;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends AppCompatActivity implements LocationListener {
private float distance;
private float[] distfloat = new float[1];
private final LatLng POINT = new LatLng(0, 0); //longitudine e latitudine
LocationManager locationManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
LatLng sede = new LatLng(45.012447, 7.621013);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(POINT, 1));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
map.addMarker(new MarkerOptions().position(sede).title("Soluzioni"));
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
if(provider != null & !provider.equals(""))
{
Location location = locationManager.getLastKnownLocation(locationManager.GPS_PROVIDER);
locationManager.requestLocationUpdates(provider, 2000, 1, this);
Location locationSede = new Location("Sede");
locationSede.setLatitude(45.012447);
locationSede.setLongitude(7.621013);
distance = location.distanceTo(locationSede); //LINE NUMBER 61
// location.distanceBetween(sede.latitude,sede.longitude,location.getLatitude(),location.getLongitude(),distfloat);
if(location!=null)
{
onLocationChanged(location);
}
else{
Toast.makeText(getApplicationContext(),"Location not found, GPS disabled.",Toast.LENGTH_LONG ).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"Provider is null.",Toast.LENGTH_LONG).show();
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
}
#Override
public void onLocationChanged(Location location) {
Toast.makeText(this,"Latitude: " + location.getLatitude() + "\nLongitude: " + location.getLongitude(),Toast.LENGTH_LONG ).show();
TextView textView2 = (TextView) findViewById(R.id.textview2);
TextView textView3 = (TextView) findViewById(R.id.textview3);
TextView textView4 = (TextView) findViewById(R.id.textview4);
String distanza = String.valueOf(distance);
//String distanza = String.valueOf(distfloat[0]);
textView2.setText("Latitude="+location.getLatitude());
textView3.setText("Longitude="+ location.getLongitude());
textView4.setText("Distance="+ distanza);
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prova.mapapplicationprove">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- Per usare il GPS -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.prova.mapapplicationprove.MainActivity" />
</activity>
</application>
</manifest>
I think you should put
distance = location.distanceTo(locationSede); //LINE NUMBER 61
into method
#Override
public void onLocationChanged(Location location) {
}
It'll look like
#Override
public void onLocationChanged(Location location) {
if (location != null){
Location locationSede = new Location("Sede");
locationSede.setLatitude(45.012447);
locationSede.setLongitude(7.621013);
int distance = location.distanceTo(locationSede);
}
}
If you want to calculate distance between 2 points then you can use to Location.distanceBetween( A.Latitude, A.Longitude, B.Latitude, B.Longitude, result);
See below code how to impliment in your code
float[] result = new float[1];
Location.distanceBetween(location.getLatitude(), location.getLongitude(), locationSede.getLatitude(), locationSede.getLongitude(), result);
Log.e("TAG Result",""+result); //Here result is your distance
double km = result * 0.001;
Log.e("TAG Result",""+km); //Here distance in kilometer
Here when you want to distance in kilometer that time total distance with multiply 0.001 as like distancein_km=total_dis*001
I resolve my problem, the error is caused by the provider: I use locationManager.allProvider(); and in this way it works.
Thanks anyway

I cant get latitude and longitude in lollipop.It works fine in other versions and maximum sdk is 22

I cant get latitude and longitude in lollipop.It works fine in other versions like gingerbread and kitkat and maximum sdk is 22. I have given
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Java code .
package com.example.project2;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.TextView;
import android.util.Log;
public class MainActivity extends Activity implements LocationListener {
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; // 1 meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 10 * 1; // 10 sec
protected LocationManager locationManager;
protected Context context;
protected boolean gps_enabled, network_enabled;
TextView txtLat;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.t1);
locationManager = (LocationManager)getSystemService(Context.Location_Service);
// getting GPS status
gps_enabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
network_enabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVID ER);
if (gps_enabled) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
} else if (network_enabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
};
}
#Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.t1);
txtLat.setText("Latitude:"+ location.getLatitude() + ", Longitude:"
+ location.getLongitude());
}
#Override
public void onProviderDisabled(String provider) {
Log.d("Latitude", "disable");
}
#Override
public void onProviderEnabled(String provider) {
Log.d("Latitude", "enable");
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras){
Log.d("Latitude", "status");
}
}
I did it in Eclipse Juno.My main intention is to get location and send to another mobile which i provided.But first I am not getting any location.
Please go through the following links.
Location issue with lollipop
Retrieve current location
It may help you. If not, let me know.
Avoid using this old method and look at Making Your App Location-Aware

Get Location From Offline Application

I'd like to get Geo location by using GPS provider. So my code will be like this
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
LocationManager lm;
TextView textLatitude, textLongitude;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textLatitude = (TextView)findViewById(R.id.textLatitude);
textLongitude = (TextView)findViewById(R.id.textLongitude);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
/* Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);*/
}
public void onResume() {
super.onResume();
setup();
}
public void onStart() {
super.onStart();
boolean gpsEnabled, networkEnabled;
gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.d("LocationService","GPS Status: "+gpsEnabled);
if(!gpsEnabled) {
networkEnabled =
lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!networkEnabled) {
Intent intent =
new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
}
}
public void onStop() {
super.onStop();
lm.removeUpdates(listener);
}
public void setup() {
lm.removeUpdates(listener);
String latitude = "Unknown";
String longitude = "Unknown";
Location gpsLocation = requestUpdatesFromProvider(
LocationManager.GPS_PROVIDER, "GPS not supported");
if(gpsLocation != null) {
Log.d("Location Service","GET FROM GPS");
latitude = String.format("%.7f", gpsLocation.getLatitude());
longitude = String.format("%.7f", gpsLocation.getLongitude());
}
textLatitude.setText(latitude);
textLongitude.setText(longitude);
}
public Location requestUpdatesFromProvider(final String provider
, String error) {
Location location = null;
if (lm.isProviderEnabled(provider)) {
lm.requestLocationUpdates(provider, 0, 0, listener);
Log.d("LocationService","Requesting...");
location = lm.getLastKnownLocation(provider);
//Log.d("LocationSerivce", "Geo :"+location.getLatitude());
} else {
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
return location;
}
public LocationListener listener = new LocationListener() {
public void onLocationChanged(Location location) {
textLatitude.setText(String.format("%.7f", location.getLatitude()));
textLongitude.setText(String.format("%.7f",location.getLongitude()));
}
public void onProviderDisabled(String provider) { }
public void onProviderEnabled(String provider) { }
public void onStatusChanged(String provider
, int status, Bundle extras) { }
};
}
The result is ... IT DOESN'T WORK. What have I done wrong?
I've also added permission to manifest file already.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.locationservice"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name
="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.locationservice.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I search a lot from Internet and I got that it'll work if I combine with Network provider and I have to use internet to get my location. This is not what I want.
I want to get Location from GPS only because I'll use for offline application.
Could you give me any great suggestion. I'll thanks a lot

LocationManager requestLocationUpdates not working

I Have This Creepy problem. i am trying to get the location of my emulator. it working fine when i get the location of my emulator. but when i change my location coordinates nothing happens. gps is working fine.
Here is my code
Main.java
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
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.view.Menu;
import android.widget.TextView;
public class Main extends Activity {
TextView tvStatus;
LocationManager lm;
boolean gpsEnabled;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvStatus = (TextView) findViewById(R.id.textView1);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.d("", "GPS is Active");
Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
tvStatus.setText(l.getLatitude()+" , "+l.getLongitude());
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new LocationListener() {
#Override
public void onStatusChanged(String arg0, int arg1,
Bundle arg2) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLocationChanged(Location arg0) {
tvStatus.setText("GPS ENABLED: " + gpsEnabled
+ "\nLatitude: " + arg0.getLatitude()
+ "\nLongitude: " + arg0.getLongitude());
}
});
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.enabelinglocationprovider"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.enabelinglocationprovider.Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Samsung phones have this problem. There is hack to this. You need to kick the locationmanager on the butt to get the latest location from the maps cache.
God.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
new LocationListener() {
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onLocationChanged(final Location location) {
}
});
currentLocation = God.locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Call getLastKnownLocation after kicking the requestLocationUpdates with 0's.
It happens with emulators, try rebooting the emulator.
Or, close both eclipse and emulator and start both again

Auto Sends GPS Coordinates via SMS

I made an Application that shows my GPS coordinates (Langitude and Latitude) number, which designed with out a map. But I would like to send the lat and long to mobile number/phone number Automatically (no need a send button) every time I open this Application. Anyone can help me..
Gps.java
package Sample.gps.send;
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 Gps extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_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 location is: " +
"Latitude = " + loc.getLatitude() +
"Longitude = " + 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)
{
}
}
}
Here is for the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Sample.gps.send"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".UseGps"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
</manifest>
Here MyLocationListener is an inner class. Can anyone tell how to retrieve the coordinates whenever onLocationChanged method is called? The location is displayed using a Toast. Is it possible to get the coordinates by calling any method from onCreate()?
See, http://mobiforge.com/developing/story/sms-messaging-android. That tutorial will show you how to send an SMS, using that you should be able to figure out what you need to do.
Please use the code tags when posting code samples :-)

Categories

Resources