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 7908397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:54:57+00:00 2026-06-03T11:54:57+00:00

I am creating an Android application that stores a couple of conditions like Location,

  • 0

I am creating an Android application that stores a couple of conditions like Location, Time, Contact and Battery level. What I intend for my application to do is to store these conditions along with some phone setting changes that the user wants to activate if these conditions are met. It would be better if I put my questions in a list :

  1. How do I check the Location of the device at regular intervals ? Is there a listener service (like for the Contacts option the TelephonyManager can be used) that can be used to listen for a callback in case the device location changed ?
  2. Is there a way to schedule a particular function to be called based on Time in Android ?
  3. Is there a way to call a particular function when the battery level of the device changes or the device is charging or unplugged ?
  • 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-06-03T11:55:00+00:00Added an answer on June 3, 2026 at 11:55 am

    Here’s your answer point wise:

    1) You can use LocationManager to get the location of your device.

    LocationManager locationManager = (LocationManager) 
    
    this.getSystemService(Context.LOCATION_SERVICE);
    
    
    
    LocationListener locationListener = new LocationListener() 
    {
    
    
     public void onLocationChanged(Location location) 
     {
    
          makeUseOfNewLocation(location);  //here you get the new location
      }
    
        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, locationListener);
    

    You can also use GeoCoder class to exactly point out the address using the longitude and latitude received from locationManager.
    Detail tutorial here – LocationManager

    2) You can schedule the particular function to be called – using BroadcastReceiver and AlarmManager service.

    private void setRecurringAlarm(Context context) {

    // we know mobiletuts updates at right around 1130 GMT.
    // let's grab new stuff at around 11:45 GMT, inexactly
    Calendar updateTime = Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
    updateTime.set(Calendar.HOUR_OF_DAY, 11);
    updateTime.set(Calendar.MINUTE, 45);
    
    Intent downloader = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
            0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarms = (AlarmManager) getActivity().getSystemService(
            Context.ALARM_SERVICE);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            updateTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, recurringDownload);
    

    }

    Detail tutorial BroadCastReceiver and AlarmManager

    So, if you want you can recurrently check for the present location of device ( using LocationManager as shown in point 1) inside OnReceive of your BroadCastReceiver.

    3) There is a BroadCastReceiver to catch when BatteryLevel changes as below:

    private BroadcastReceiver mBatInfoReceiver 
    
    = new BroadcastReceiver(){
    
        @Override
        public void onReceive(Context arg0, Intent intent) {
            int level = intent.getIntExtra("level", 0);
            // do something...
        }
    }
    
        registerReceiver(this.mBatInfoReceiver, 
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    

    For plugin or charging use following code:

    // Are we charging / charged?
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    
    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                         status == BatteryManager.BATTERY_STATUS_FULL;
    
    
    // How are we charging?
    
    int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    boolean usbCharge = chargePlug == BATTERY_PLUGGED_USB;
    boolean acCharge = chargePlug == BATTERY_PLUGGED_AC;
    

    I Hope All this will help you…

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

Sidebar

Related Questions

I'm creating an android application that gets the current time in a different country/time-zone.
Suppose I am creating an Android application that's like an SMS app. The requirements
I'm creating an Android application that requires the following: Data from RSS feed gets
I'm creating an Android application that requires me to create a bitmap of the
I am creating an android application that requires me to call is in different
I'm creating a splash screen that will display while my Android application loads. I'd
I am creating a mobile application on Android that requires devices to communicate with
I am creating an Android application that connects to the Fogbugz XML API (sends
I'm creating an Android application that essentially does nothing but adding '1' to numbers
I'm New to android, and I'm creating an application that uses the twitter api,

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.