Skip to main content

How to take raw data from an android mobile phone's GPS..?

Hello friends
                        Today i am gonna to discuss about taking raw data or coordinate from an android mobile GPS device.

Let's Start................

Step:1


Just enter into programming mode in android studio.
If you don't know that how to do that please read this post.

Step:2



Now just make a new class as show in figure and name it BootService.

Step:3

Now extends Service and implements LocationListener as shown in figure below.


Step:4

Now just copy and paste following code into BootService class.




LocationManager lm;


@Override
public int onStartCommand(Intent intent, int flags, int startId)
{

lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this);

return START_STICKY;
}

@Override
public void onLocationChanged(Location location) {

try{

Toast.makeText(this, "GPS Values Found: " + String.valueOf(location.getLongitude()) + " : " + String.valueOf(location.getLatitude()), Toast.LENGTH_SHORT).show();
}catch(Exception ex){
Log.i("Error in getting location valus", ex.getMessage());
}
}

@Override
public void onProviderDisabled(String provider) {
/* this is called if/when the GPS is disabled in settings */

/* bring up the GPS settings */
//Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
//startActivity(intent);
Toast.makeText(this, "GPS Disabled", Toast.LENGTH_SHORT).show();
}

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

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
/* This is called when the GPS status alters */
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}


@Override
public IBinder onBind(Intent arg0)
{
return null;
}

Step:5

Now Just copy and paste following permissions into manifest file.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

<service android:name=".BootService"></service>



Step:6
Now just connect your mobile phone to pc via USB cable and click on run in android studio.This will install app into your mobile,where you can see GPS values as toast message.

IF YOU HAVE ANY QUERY PLEASE COMMENT BELOW

Comments

Popular posts from this blog

Real life Jarvis-Talk With Your Computer like Jarvis in Iron Man ....!

By:Prayag nao                                            Code to Make your Computer like Jarvis New Speech macro..>> Choose Advanced and change the code like this.. <speechMacros>   <command>     <listenFor></listenFor>   </command> </speechMacros> You have to add a commands  <listenFor>........</listenFor> - computer listens the words you specify here and respond accordingly. <speak>............</speak> - computer speaks what is written in this field according to the command which it got. Similarly, You can Edit more commands in the same way.   <speechMacros> <command> <listenFor>What's going on dude</listenFor> <speak>Nothing special tony</speak> </command> </speechMacros> ...

Types of gears used in daily life

By:Prayag nao Spur Gears: Spur gears are the most common type used. Tooth contact is primarily rolling, with sliding occurring during engagement and disengagement. Some noise is normal, but it may become objectionable at high speeds.   Rack and Pinion. Rack and pinion gears are essentially a linear shaped variation of spur gears The spur rack is a portion of a spur gear with an infinite radius. Internal Ring Gear: Internal gear is a cylindrical shaped gear with the meshing teeth inside or outside a circular ring. Often used with a spur gear. Internal ring gears may be used within a planetary gear arrangement. ...

How does a handpump work ?

The most common tool to access a life source like water — this innovation boasts of none of the accolades that modern machines enjoy. Yet the simplicity and efficiency of design drives a sea of devices that permeate our lives at home and in industries. The unsung hero that India should be particularly proud of is called India Mark II. A human-powered pump designed to lift water from a depth of 50 m or less, it is the world’s most widely used water hand pump. It was designed in 1970 through the joint efforts of the government of India, UNICEF and WHO. Its purpose was to address the deathly problem of paucity of water and draught in rural areas of developing nations. By the mid 1990s, five million of the pumps had been manufactured and installed around the world. Hand Pump Parts: Handle Pump rod water outlet Piston Piston valve Foot valve Rising main Suction lift What does it do? Simply defined, hand pumps are manually operated pumps that use human power and ...