Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:31:20+00:00 2026-05-31T15:31:20+00:00

If u want to fire (alarm,notification etc) on user’s phone based on location found,

  • 0

If u want to fire (alarm,notification etc) on user’s phone based on location found, so i want to know about which method is needs to use.
Its like location based alarm.
please show me some example, it will very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:31:22+00:00Added an answer on May 31, 2026 at 3:31 pm

    Use the below code

    import java.util.Timer;
    import java.util.TimerTask;
    
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.provider.Settings;
    
    import com.gs.mobile.Constants;
    import com.gs.mobile.R;
    
    public class MyLocation {
        private Timer timer1;
        private LocationManager lm;
        private LocationResult locationResult;
        private boolean gps_enabled=false;
        private boolean network_enabled=false;
        private AlertDialog.Builder dialog;
    
        public boolean getLocation(final Context context, LocationResult result){
            //I use LocationResult callback class to pass location value from MyLocation to user code.
            locationResult=result;
            if(lm==null)
                lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    
            //exceptions will be thrown if provider is not permitted.
            try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
            try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
    
            //don't start listeners if no provider is enabled
            if(!gps_enabled && !network_enabled){
                dialog = new AlertDialog.Builder(context);
                dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled));
                /*dialog.setPositiveButton(context.getResources().getString(R.string.open_location_settings), new DialogInterface.OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                        // TODO Auto-generated method stub
                        Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
                        context.startActivity(myIntent);
                        Util.getGPS((Activity) context,locationResult);
                    }
                });
                dialog.setNegativeButton(Constants.TEXT_CANCEL, new DialogInterface.OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                        // TODO Auto-generated method stub
    
                    }
                });*/
                dialog.show();
    
            }
             if(gps_enabled)
                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
            if(network_enabled)
                lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
            timer1=new Timer();
            timer1.schedule(new GetLastLocation(), 20000);
            return true;
        }
    
        LocationListener locationListenerGps = new LocationListener() {
            public void onLocationChanged(Location location) {
                timer1.cancel();
                locationResult.gotLocation(location);
                lm.removeUpdates(this);
                lm.removeUpdates(locationListenerNetwork);
            }
            public void onProviderDisabled(String provider) {}
            public void onProviderEnabled(String provider) {}
            public void onStatusChanged(String provider, int status, Bundle extras) {}
        };
    
        LocationListener locationListenerNetwork = new LocationListener() {
            public void onLocationChanged(Location location) {
                timer1.cancel();
                locationResult.gotLocation(location);
                lm.removeUpdates(this);
                lm.removeUpdates(locationListenerGps);
            }
            public void onProviderDisabled(String provider) {}
            public void onProviderEnabled(String provider) {}
            public void onStatusChanged(String provider, int status, Bundle extras) {}
        };
    
        class GetLastLocation extends TimerTask {
            @Override
            public void run() {
                 lm.removeUpdates(locationListenerGps);
                 lm.removeUpdates(locationListenerNetwork);
    
                 Location net_loc=null, gps_loc=null;
                 if(gps_enabled)
                     gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                 if(network_enabled)
                     net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    
                 //if there are both values use the latest one
                 if(gps_loc!=null && net_loc!=null){
                     if(gps_loc.getTime()>net_loc.getTime())
                         locationResult.gotLocation(gps_loc);
                     else
                         locationResult.gotLocation(net_loc);
                     return;
                 }
    
                 if(gps_loc!=null){
                     locationResult.gotLocation(gps_loc);
                     return;
                 }
                 if(net_loc!=null){
                     locationResult.gotLocation(net_loc);
                     return;
                 }
                 locationResult.gotLocation(null);
            }
        }
    
        public static abstract class LocationResult{
            public abstract void gotLocation(Location location);
        }
    }//MyLocation-class
    

    Calling this from an activity is as shown below

    /* Used to Get Device GPS Location
         * <uses-permission android:name=�android.permission.ACCESS_FINE_LOCATION�>
         */
        public static LocationResult locationResult = new LocationResult(){
    
            @Override
            public void gotLocation(Location location) {
                // TODO Auto-generated method stub
    
            }
        };
    
        public static void getGPS(Activity _activity){
            MyLocation myLocation = new MyLocation();
            myLocation.getLocation(_activity, locationResult);
    
        }//getGPS()
    
        public static void getGPS(Activity _activity,LocationResult locationResult){
            MyLocation myLocation = new MyLocation();
            myLocation.getLocation(_activity, locationResult);
    
        }//getGPS()
    

    every time when the lat and lang changed Your public void gotLocation(Location location) method will be called where you can check whether the location comes under you expected or not.

    If you want, even you can make use of the URL http://maps.googleapis.com/maps/api/geocode/xml?address=37.4188514,-122.0874526&sensor=true

    where you can get the name of that lat,lang by sending to this google service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a service which fire alarm manager in every 1 min
i want to make a service which fire alarm manager in every 5 min
I want to fire an alarm that will ring after 2 secs. How to
I want for an event to fire every hour (at 5:00, 6:00, 7:00, etc...).
I have a custom event that I want to fire using jQuery's trigger method:
When the user clicks a button, I want to fire the ListGrid Selection event.
for example i want to have an alarm that will fire every sunday at
I want to fire some method on voice detection. For Example, Just like in
I want to add a fire alarm function to my app. I think the
I want to fire an event when the user select a file. Doing so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.