I'm trying to make a simple Android application to get the current location using GPS or a network provider (WIFI or Tower), but I ran into such problems trying to get it to work on Android. It won’t start, it gave me an exception, I don’t know why.
This is the code. It is so simple because I want to check the location, and later I will add some functions and functions.
main:
package com.GpsTesting;
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_TestActivity extends Activity{
String location_text="";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
location_text= "latitude: "+lat+"longitude: "+lng;
Toast.makeText(getApplicationContext(), location_text, Toast.LENGTH_SHORT).show();
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);
}
}
manifesto:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.GpsTesting"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.ACCESS_FINE_LOCATION">
<activity android:name=".GPS_TestActivity"
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_COARSE_LOCATION" />
</manifest>
So, is there a problem in the code? I do this with an online tutorial (from android developer and other sites).
Thank you so much.
Notes Added:
** . , eclipse ( USB ).
, , !!! ( .apk , , !!)
- , ? - ??
, , Android. , , ...
:
E-mail .apk, bin ( eclipse )... , , .apk, bin, onw ( ) , . , apk ... , eclipse ?
;) **
;)
Android: = "android.permission.ACCESS_FINE_LOCATION"
, ( , ).
, , .