Here is code of my Android app.
MainActivity.java
public class MainActivity extends Activity {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
protected LocationManager locationManager;
protected Button retrieveLocationButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MyTag", "first");
retrieveLocationButton = (Button) findViewById(R.id.button1);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
retrieveLocationButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showCurrentLocation();
Log.d("MyTag", "Second");
}
});
}
protected void showCurrentLocation() {
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.d("MyTag", "Third"+location);
if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(MainActivity.this, message,
Toast.LENGTH_LONG).show();
Log.d("MyTag", "Fifth");
}
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Log.d("MyTag", "sixth");
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(MainActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MainActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MainActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
}
BootReceiver.java
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent){
context.startService(new Intent(context,MainActivity.class));
Log.d("kkkkkkkk","bootReceive");
}
}
AndroidMainfest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pragmatic.pragmaticgps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.REBOOT"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MainActivity"></service>
<receiver
android:name=".receiver..MainActivity"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
<receiver android:name=".BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
I wanted this App to get GPS cordinates i.e. Latitude/Longitude and display it via a toast (which it does.) I also wanted that whenever the mobile is rebooted this App should start automatically and run in background 24x7 but on a real Android mobile when I switch on the Phone, App craches and a Pop up Appears asking to Force Close it. what is wrong in the code ? Sorry for asking the bug directly but I dont know much about Android.
Thank you.
Feels like the bug lies in here:
context.startService(new Intent(context,MainActivity.class));
You can start MainActivity as a Service since it's not a Service, it's an Activity. To start an Activity you should call
context.startActivity(new Intent(context,MainActivity.class))
Also, in this situation it would be better to organize MainActivity as a Service since it's a pretty bad idea to start an Activity directly from a BroadcastReceiver. Hope this helps.
Related
Hello i am new to android development . I want to get my current Location but i need to wait for my listener start working . The problem is that i dont change position so the listener cant work (?) !
Here is the sample of my code
My listener :
locationListener = new LocationListener() {
#Override
public void onLocationChanged(Location location) {
textView.append(location.getLongitude() + "\n" + location.getLatitude() + "\n");
// just monitoring
lat = location.getLatitude();
lng = location.getLongitude();
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
};
and i request the updates on this
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300, 0, locationListener);
So if i am not mistaken the gps will take the new position based on time (300ms) or based on distance which is 0 so its gonna work ?? Should i wait some time to start taking it? How long? more than 2 minutes?
I got wi-fi open and gps of course this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Details" />
<activity android:name=".LoginMenu" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity android:name=".Road" />
<activity android:name=".LoopActivity" />
<activity android:name=".Pedestrians"></activity>
</application>
Many Thanks in regards
I'm litte ashamed. But cant find what's wrong.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.szymon.gpslab1"
android:versionCode="15"
android:versionName="4.0.3">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
It's my manifest.
and here's my code:
public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
LocationListener locationListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
private class MyLocationListener implements LocationListener{
#Override
public void onLocationChanged(Location location) {
System.out.println("ZMIENIAMY SIĘ, zmieniamy siebie");
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
}
}
}
Im using the newest android studio (intellij) with embedded (?) emulator. Phone is out of options.
ANd here what i've got:
FATAL EXCEPTION: main
Process: com.example.szymon.gpslab1, PID: 3274
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.szymon.gpslab1/com.example.szymon.gpslab1.MainActivity}: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
I belive this is stupid mistake, but I've never like developed for android, im the javaman, and i've reached every tutorial on net, cant find answer.
Ah and y, I have location on in my emulator.
This is a common exception if your target SDK is 23 in your build.gradle.
Android 6.0 / sdk 23 introduces a new way of requesting permissions.
See the link below for how to handle permissions:
https://developer.android.com/training/permissions/index.html
There are some questions regarding this issue but I could not find any method works without problem. I implemented the version of the project with GPS provider and now I want to implement a version which can find the location of user without GPS, just using network provider such as Wifi. I tried this but it is not working (I could not get the "done" message in any way):
public class MapsActivity extends FragmentActivity {
double latitude;
double longitude;
LocationManager locationManager;
android.location.LocationListener networkLocationListener;
Location location;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
networkLocationListener = new android.location.LocationListener() {
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Log.d("->", "done.");
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networkLocationListener);
}
...
Also, this is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.doruk.myapplication">
<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" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/orange"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".ConnectionChangeReceiver"
android:label="NetworkConnection">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
</application>
</manifest>
Can you see the problem? What you advise at this point? Is there a better way?
Dorukhan Arslan
- You can use GoogleclientAPi, as locationmanager has been
Deprecated
-Using FusedLocationAPi it will automatically discover the provider to find the location.
- https://developer.android.com/google/auth/api-client.html have a look
on this
- Here is one exampleprotected void createLocationRequest() {
LocationRequest mLocation = LocationRequest.create();
GoogleAPiClient mgoogle;
/*enter code here
* Set the update interval
*/
mLocation.setSmallestDisplacement(500); // 2km
mLocation.setInterval(180000);// 3 min
mLocationRequest.setFastestInterval(120000);// 2 min
mLocation.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (mgoogle == null) {
mgoogle = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
mgoogle.connect();
}
}
It's a sample and implementing OnConnectionFailedListener,
ConnectionCallbacks, com.google.android.gms.location.LocationListener above 3 interfaces you can get the continuos Location.
getLastLocation Method Of LocationRequest Class will give you Location.
onLocationChanged Method will give you Your desired output.
You can use IP address of user for getting approx location.
I am trying to make an app which is using parse library for push notifications.I followed the tutorials from parse.com but its not working.
I am getting error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.robotrackerclient/com.robotrackerclient.MainActivity}:
java.lang.IllegalArgumentException: listener==null
I think the problem is in the code.I am having a main activity which is launching activity of the app.I am putting the parse.initialize() code in the onCreate method of main activity.Is this creating the problem? There is one more error: You must call parse.initialize(..) before using the parse library.
The Main Activity is just a simple class getting the lattitude and longitude of the current location and pushing it.
public class MainActivity extends Activity {
private String imei_code_of_device;
private LocationManager lm;
private LocationListener locationListener;
TelephonyManager mngr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Specify an Activity to handle all pushes by default.
//PushService.setDefaultPushCallback(this, MainActivity.class);
Parse.initialize(this, "APP_KEY", "CLIENT_KEY");
PushService.setDefaultPushCallback(this, MainActivity.class);
mngr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
imei_code_of_device=mngr.getDeviceId();
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);
locationListener = new MyLocationListener();
if ( !lm.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
buildAlertMessageNoGps();
}
else{
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
10000,
0,
locationListener);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,10000,0,locationListener);
}
}
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
private class MyLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
if (loc != null) {
ParseObject po=new ParseObject("LatLang");
po.put("imei_code",imei_code_of_device);
po.put("latitude",loc.getLatitude());
po.put("longitude",loc.getLongitude());
po.saveInBackground();
Toast.makeText(getBaseContext(),"Location changed : Lat: " + loc.getLatitude() +" Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();
}
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my androidmenifest file:
I completed these steps with help of the tutorials available on parse.com.I included everything which parse.com tutorial said me to include.I am not getting the point of Application.Because I have to parse in the one of the activities only and it is not the first activity to be launched.So I dont want to initialize parse at my application startup.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robotrackerclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission android:name="com.robotrackerclient.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.robotrackerclient.permission.C2D_MESSAGE" />
<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>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.robotrackerclient" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
</manifest>
You should use your app and client keys instead of default values APP_KEY and CLIENT_KEY in this line:
Parse.initialize(this, "APP_KEY", "CLIENT_KEY");
which you can get after signing up at Parse.
OKay thank you very much for helping I am able to send push to parse.com.The mistake was in the manifest file.I updated the menifestfile with providing android:name=."ParseActivity" under the application tag.Then I defined the initialization in the ParseActivity class.
Now can anybody tell how to get the pushed data over server back on another device using the same set of keys?
i am new to android.i need to get lattitude and logitude of current location.but it shows null pointer exception in location.here below i added my code.
LocationManager lm;
Location location;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
location=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
SaveLocation(location);
}
private void SaveLocation(Location location) {
Long time=new GregorianCalendar().getTimeInMillis()+1*60*1000;
Intent intent=new Intent(MainActivity.this,AlarmReceiver.class);
intent.putExtra("lat",location.getLatitude());
intent.putExtra("lon",location.getLongitude());
AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,time,PendingIntent.getBroadcast(this,1,intent,PendingIntent.FLAG_UPDATE_CURRENT));
}
my androidmanifasted file is like
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.gps.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>
Anyone can help me?
Your location is null because you instantly try to get the last known location after you create a LocationManager. In this time (some milliseconds) your device can't find any locations.
You need a time gap between your initalization of your LocationManager and the getLastKnownLocation-method. I would recommend to put the getLastKnownLocation-method in an OnClick event on a button to create a time gap.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
/....
}
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
location=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
SaveLocation(location);
}
});
Your Location object is null, since there is no last known location stored.
location=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// Check if last known location exists.
if(location != null) {
SaveLocation(location);
}
//to find the current latitude and longitude of user
public String getMyLocation(){
locationManager=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location!=null){
loc[0]=location.getLatitude();
loc[1]=location.getLongitude();
Log.d("STATUS n ", loc[0]+"entered 1"+loc[1]);
}
else {
location=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(location!=null)
{
loc[0]=location.getLatitude();
loc[1]=location.getLongitude();
Log.d("STATUS n","else"+loc[0]+"entered 1"+loc[1] );
}
}
return getPlace(loc);
}