I have litle problem with my app.
I get location from GPS or Network and everything works but...
if I get location from GPS and I turn off GPS from phone when I do not get location from Network
so.. I need help,
How to make when I turn off GPS switch on Network
my code:
public class Background_work extends Service implements LocationListener{
static String TAG="Service Created";
private Timer timer = new Timer();
private TimerTask task;
int count = 0;
LocationManager lm;
// Platuma ilguma
double lat,log;
//Tikrina kas ijungta
boolean GPSStatus = false;
boolean NetworkStatus = false;
public void setX(double X){
lat = X;
}
public void setY(double Y){
log = Y;
}
public double getX(){
return lat;
}
public double getY(){
return log;
}
public int onStartComand(Intent intent, int flags, int startId){
Toast.makeText(this, "Setver Started", Toast.LENGTH_LONG).show();
return Service.START_NOT_STICKY;
}
public void onCreate() {
super.onCreate();
Log.d(Background_work.TAG, "Service Created");
}
#Override
public void onStart(Intent intent, int startId) {
Log.d(Background_work.TAG, "Service started");
subscribeToLocationUpdates();
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
if(location != null){
setX(latitude);
setY(longitude);
}
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public void subscribeToLocationUpdates() {
this.lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
// GPS status
GPSStatus = this.lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Network status
NetworkStatus = this.lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.i("", "GPS" + GPSStatus + " network" + NetworkStatus);
if(GPSStatus == true){
this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);
}else if(NetworkStatus == true){
this.lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this);
}else if(NetworkStatus == true && GPSStatus == true){
this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);
}
}
}
Related
One of my android app needs to get gps positions, if the app is in destroy state. My app get gps positions currently when it is in running(active) and pause(background) modes. But when I destroyed my app, the service is running but the LocationListener onLocationChanged(Location location) not calling. How can I deal this type of issues?.
public class LocationFinder extends Service {
public static double lat, lng;
LocationManager locationManager;
public void onDestroy() {
super.onDestroy();
}
#Override
public void onCreate() {
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.v("location", "===>location ed onStartCommand " + lat + "==>"
+ lng);
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
getLocation();
}
});
return START_STICKY;
}
final LocationListener locationListener = new LocationListener() {
// this method is not called when we destroyed the app. i want to call this method even app is in destoyed.
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
Toast.makeText(
getApplicationContext(),
"Location Finder : onLocation Changed "
+ location.getLatitude() + " "
+ location.getLongitude(), Toast.LENGTH_LONG)
.show();
}
public void onProviderDisabled(String provider) {
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
};
public Location getLocation() {
Variables.writeLog("Enter into getLocation : \n", false);
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(context);
Location location = null;
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
Log.v("Location", "Before");
if (locationManager != null) {
String provider = locationManager.getBestProvider(criteria, true);
boolean isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (provider != null) {
if (isGPSEnabled) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 10, 0,
locationListener);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 10, 0,
locationListener);
if (location != null) {
updateWithNewLocation(location);
} else {
location = locationManager
.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider,
10, 0, locationListener);
}
} else {
location = locationManager
.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 10, 0,
locationListener);
}
} else {
location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 10, 0,
locationListener);
}
} else {
if (locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 10, 0,
locationListener);
} else if (locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 10, 0,
locationListener);
} else if (locationManager
.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.PASSIVE_PROVIDER, 10, 0,
locationListener);
}
}
}
return location;
}
private void updateWithNewLocation(Location location) {
if (location != null) {
Log.v("location", "===>location ed " + lat);
lat = location.getLatitude();
lng = location.getLongitude();
Variables.writeLog("Lat :" + lat + " lng : " + lng, false);
}
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
Hey you need to create background Service which will work in the background and do that job for you check those links
link 1
link 2
You can start this services when your activity is destroyed and the stop it when your app is resumed
You Have to run background service which will recieve locations using gps.
public class AndroidLocationServices extends Service {
WakeLock wakeLock;
private LocationManager locationManager;
public AndroidLocationServices() {
// TODO Auto-generated constructor stub
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
PowerManager pm = (PowerManager) getSystemService(this.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DoNotSleep");
// Toast.makeText(getApplicationContext(), "Service Created",
// Toast.LENGTH_SHORT).show();
Log.e("Google", "Service Created");
}
#Override
#Deprecated
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
new ToggleGPS(getApplicationContext()).turnGPSOn();
// Toast.makeText(getApplicationContext(), "Service Started",
// Toast.LENGTH_SHORT).show();
Log.e("Google", "Service Started");
locationManager = (LocationManager) getApplicationContext()
.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
5000, 5, listener);
}
private LocationListener listener = new LocationListener() {
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.e("Google", "Location Changed");
if (location == null)
return;
if (isConnectingToInternet(getApplicationContext())) {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
try {
Log.e("latitude", location.getLatitude() + "");
Log.e("longitude", location.getLongitude() + "");
jsonObject.put("latitude", location.getLatitude());
jsonObject.put("longitude", location.getLongitude());
jsonArray.put(jsonObject);
Log.e("request", jsonArray.toString());
new LocationWebService().execute(new String[] {
Constants.TRACK_URL, jsonArray.toString() });
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
};
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
new ToggleGPS(getApplicationContext()).turnGPSOff();
wakeLock.release();
}
public static boolean isConnectingToInternet(Context _context) {
ConnectivityManager connectivity = (ConnectivityManager) _context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
}
I found this code in github. it works , I have used it in my appilcation.
GITHUB LINK
public class LocationService extends Service{
private LocationManager locationMangaer=null;
private LocationListener locationListener=null;
private static final String TAG = "Debug";
private Boolean flag = false;
public static String cityName=null;
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
super.onCreate();
Log.d("Location Serive","Started");
locationMangaer = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
flag = displayGpsStatus();
boolean c=isOnline();
if(flag)
{
locationMangaer.removeUpdates(locationListener);
Criteria crit2 = new Criteria();
crit2.setAccuracy(Criteria.ACCURACY_FINE);
String provider2 = locationMangaer.getBestProvider(crit2, false);
Toast.makeText(getApplicationContext(), provider2, Toast.LENGTH_LONG).show();
locationMangaer.requestLocationUpdates(provider2,1, 1,locationListener);
}
else if(c)
{
locationMangaer.removeUpdates(locationListener);
Criteria crit = new Criteria();
crit.setPowerRequirement(Criteria.POWER_LOW);
crit.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = locationMangaer.getBestProvider(crit, false);
Toast.makeText(getApplicationContext(), provider, Toast.LENGTH_LONG).show();
locationMangaer.requestLocationUpdates(provider,1, 1,locationListener);
}
else
{
//Nothing Available
}
Log.d("Internet",Boolean.toString(c));
}
/*net Enabled or Not*/
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
/*----------Method to Check GPS is enable or disable ------------- */
#SuppressWarnings("deprecation")
private Boolean displayGpsStatus() {
ContentResolver contentResolver = getBaseContext().getContentResolver();
boolean gpsStatus = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.GPS_PROVIDER);
if (gpsStatus) {
return true;
} else {
return false;
}
}
/*----------Listener class to get coordinates ------------- */
private class MyLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
Log.d("Location Changed", "location:");
Log.d("Latitude", Double.toString(loc.getLatitude()));
Log.d("Longitude",Double.toString(loc.getLongitude()));
Toast.makeText(getApplicationContext(), Double.toString(loc.getLatitude()), Toast.LENGTH_LONG).show();
double p=loc.getLongitude();
double q=loc.getLatitude();
LocationChecker(p,q);
}
#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
}
}
From This Activtiy I called the service
But as soon as remove my application from recent apps through swipe the location listener stops working and does not show any location change update but if the app is running then it works fine.
public class Dashboard extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
Intent l = new Intent(getApplicationContext(),LocationService.class);
getApplicationContext().startService(l);
}
Do you stop service in onDestroy of your activity ?
You could also override method onStartCommand and use START_STICKY value.
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Received start id " + startId + ": " + intent);
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
}
UPDATE1
You could start your service in a separate process. See doc :
http://developer.android.com/guide/topics/manifest/service-element.html#proc
If the process name begins with a lowercase character, the service
will run in a global process of that name, provided that it has
permission to do so.
for instance:
<service
android:name=".LocationService"
android:process="myLocationService" [...] >
[...]
</service>
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String phonenum = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
if (phonenum.equals("111")) {
locationmanager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationlistener);
Toast.makeText(context, "The Gps values are..." + lon, Toast.LENGTH_LONG).show();
}
}
}
private static LocationListener locationlistener = new LocationListener() {
#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 void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
}
};
hi,
when i dial 111 on my dial pad my app which is pre installed on my device should toast the latitude and logitude values.I tried a sample app which displays toast message on dial of 111 making use of broadcast receiver.Above is the code which i tried.Can any help me how to get the latitude and logitude values from this fucntion.
private Location getLastBestLocation() {
Location locationGPS = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location locationNet = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
long GPSLocationTime = 0;
if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); }
long NetLocationTime = 0;
if (null != locationNet) {
NetLocationTime = locationNet.getTime();
}
if ( 0 < GPSLocationTime - NetLocationTime ) {
return locationGPS;
}
else {
return locationNet;
}}
I am trying to send GPS coordinates to server in every 1 minute interval through a background service . It invokes the service for thee first time but it doesn't repeat it .
Code for setting the alarm:
Intent gpsIntent = new Intent(CheckInActivity.this, GoogleMapService.class);
gpsPendingIntent = PendingIntent.getService(CheckInActivity.this, 0, gpsIntent, 0);
AlarmManager alarmManager_gps = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar_gps = Calendar.getInstance();
calendar_gps.add(Calendar.SECOND, 20);
alarmManager_gps.setRepeating(AlarmManager.RTC_WAKEUP, calendar_gps.getTimeInMillis(), TimeUnit.MINUTES.toMillis(1), gpsPendingIntent);
Service
public class GoogleMapService extends Service {
private boolean gps_enabled = false;
private boolean network_enabled = false;
private static Location sLocation;
private LocationManager locManager;
private LocationListener locListener = new MyLocationListener();
private CallBack callback;
#Override
public void onCreate() {
}
#Override
public IBinder onBind(Intent intent) {
Log.w(null,"GPS Service called");
locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
try {
gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
}
try {
network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) {
}
if (gps_enabled) {
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
if (network_enabled) {
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
}
callback = new CallBack() {
public void onResult(Boolean result) {
// TODO Auto-generated method stub
}
public void onProgress() {
// TODO Auto-generated method stub
}
};
return null;
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
#Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
if (location != null) {
// This needs to stop getting the location data and save the battery power.
locManager.removeUpdates(locListener);
sLocation = location;
Model.coordinates = location.getLatitude() + "," + location.getLongitude();
try{
SendGPSCoordinatesOperation task = new SendGPSCoordinatesOperation(callback);
task.execute("");
Log.w(null,"Sent");
}
catch(Exception e){
Log.w(null,"Couldn't be sent");
}
Log.w(null,"The coordinates are"+Model.coordinates);
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
EDIT : AndroidManifest code
Use this...
private void setLocationSendingAlarm() {
AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), GoogleMapService.class);
intent.putExtra("locationSendingAlarm", true);
PendingIntent pendingIntent = PendingIntent.getService(this, 987654321, intent,0);
try {
alarmManager.cancel(pendingIntent);
} catch (Exception e) {
}
int timeForAlarm=60000;
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+timeForAlarm, timeForAlarm,pendingIntent);
}
gpsPendingIntent = PendingIntent.getService(CheckInActivity.this, 0, gpsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
I am new user to Stackoverflow and this is my first question...
Question is...
How to get the periodic updates of location details? I have tried with Service class and run thread inside it but,This is called only once.
Can any one suggest me what I am doing wrong? Thank you.
Here is my code
public class MyService extends Service
{
String GPS_FILTER = "";
Thread triggerService;
LocationManager lm;
GpsListener gpsLocationListener;
boolean isRunning = true;
#Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(getApplicationContext(), "Hello",Toast.LENGTH_LONG).show();
GPS_FILTER = "MyGPSLocation";
}
#Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
triggerService = new Thread(new Runnable(){
public void run(){
try{
Looper.prepare();//Initialize the current thread as a looper.
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Toast.makeText(getApplicationContext(), "Hello1",Toast.LENGTH_LONG).show();
gpsLocationListener = new GpsListener();
long minTime = 30000; // 5 sec...
float minDistance = 10;
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
minDistance, gpsLocationListener);
Looper.loop();
}catch(Exception ex){
System.out.println("Exception in triggerService Thread -- "+ex);
}
}
}, "myLocationThread");
triggerService.start();
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
removeGpsListener();
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
private void removeGpsListener(){
try{
lm.removeUpdates(gpsLocationListener);
}
catch(Exception ex){
System.out.println("Exception in GPSService --- "+ex);
}
}
class GpsListener implements LocationListener{
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double latitude = location.getLatitude();
double longitude = location.getLongitude();
sendBroadcast(filterRes);
postdata();
}**
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
My updated answer
This Call to service class
Calendar cur_cal = Calendar.getInstance();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Intent intent = new Intent(this, MyService.class);
PendingIntent pintent = PendingIntent.getService(login.this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
public class MyService extends Service
{
String GPS_FILTER = "";
Thread triggerService;
LocationListener locationListener;
LocationManager lm;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1000; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000*60; // in Milliseconds
protected LocationManager locationManager;
boolean isRunning = true;
#Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
GPS_FILTER = "MyGPSLocation";
// locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// locationManager.requestLocationUpdates(
// LocationManager.GPS_PROVIDER,
// MINIMUM_TIME_BETWEEN_UPDATES,
// MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
// new MyLocationListener());
}
#Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
super.onStart(intent, startId);
turnGPSOn();
Toast.makeText(getApplicationContext(), "Hello1",Toast.LENGTH_LONG).show();
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES, 1.0f, locationListener);
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
// removeGpsListener();
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
// private void removeGpsListener(){
// try{
// lm.removeUpdates(locationManager);
// }
// catch(Exception ex){
// System.out.println("Exception in GPSService --- "+ex);
// }
// }
private class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location location)
{
postdata(location.getLatitude(),location.getLongitude());
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(MyService.this, message, Toast.LENGTH_LONG).show();
turnGPSOnOff();
}
public void onStatusChanged(String s, int i, Bundle b) {
// Toast.makeText(MyService.this, "Provider status changed",
// Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
// Toast.makeText(MyService.this,
// "Provider disabled by the user. GPS turned off",
// Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
// Toast.makeText(MyService.this,
// "Provider enabled by the user. GPS turned on",
// Toast.LENGTH_LONG).show();
}
}
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cur_cal.getTimeInMillis(), 60*1000, pintent);
Try Puuting things that you want to do inside run of this class,
This thread runs every 5 Seconds,
You can modify it as you want.
public class PeriodicChecker extends Thread
{
#Override
public void run()
{
while(true) {
System.out.println("Thread is doing something");
//Put Your code here
Thread.sleep(5000);
}
}
}
public OtherClass {
public static void main(String args[]) {
Thread t = new PeriodicChecker();
t.start();
}
}