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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:13:35+00:00 2026-05-31T02:13:35+00:00

I am trying to send SMS when the battery Level reached a particular value

  • 0

I am trying to send SMS when the battery Level reached a particular value from a Service. I am not getting any errors but the SMS is not been sent.

MY CODE:

          import android.app.Service;
          import android.content.BroadcastReceiver;
          import android.content.Context;
          import android.content.Intent;
          import android.content.IntentFilter;
          import android.os.BatteryManager;
          import android.os.IBinder;
          import android.telephony.SmsManager;
          import android.util.Log;
          import android.widget.Toast;


          public class BatteryStatus extends Service {
      int scale = -1;
          int level = -1;
          int voltage = -1;
          int temp = -1;
          String batteryNumber = "012345567";
          String moderate=" Battery Level is 50 ";
          String low = "Battery Level is low. Need to be charged immediately";


      public IBinder onBind(Intent intent) {
        return null;
      }

      public void onCreate() {
        super.onCreate();

        Toast.makeText(getApplicationContext(),"Service Running",  Toast.LENGTH_SHORT).show();
         //BATTERY STATUS 
        BroadcastReceiver batteryReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
                voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
                Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is  "+voltage);
                Log.e("NumberBattery ", "Number is "+batteryNumber);
            }
        };

        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        registerReceiver(batteryReceiver, filter);
        if(batteryNumber!=null && level==49){

                SmsManager bat = SmsManager.getDefault();
                bat.sendTextMessage(batteryNumber,null,moderate,null,null);
        }else if(batteryNumber!=null && level==20){
                SmsManager bat = SmsManager.getDefault();
                bat.sendTextMessage(batteryNumber, null,low, null, null);
            }

         }




           }

LOGCAT:

             03-09 03:41:40.390: E/BatteryManager(11086): level is 49/100, temp is 321, voltage is 7574
             03-09 03:41:40.390: E/NumberBattery(11086): Number is 01234567

Can you please tell what is wrong her?

  • 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-31T02:13:37+00:00Added an answer on May 31, 2026 at 2:13 am

    It’s because you never send the SMS.

    When the following line is executed:

    if (batteryNumber != null && level == 49){
    

    level has not been initialized yet.

    Change your code like this:

    @Override
    public void onReceive(Context context, Intent intent) {
        level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
        temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
        voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
        Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is  "+voltage);
        Log.e("NumberBattery ", "Number is "+batteryNumber);
        if (batteryNumber != null && level == 49) {
            SmsManager bat = SmsManager.getDefault();
            bat.sendTextMessage(batteryNumber,null,moderate,null,null);
        } else if(batteryNumber!=null && level==20){
            SmsManager bat = SmsManager.getDefault();
            bat.sendTextMessage(batteryNumber, null,low, null, null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send a sms with smslib but It did not send
I am trying to send an email from a site I am building, but
I am trying to send sms programmatically from one android emulator to another on
I'm trying to send and receive binary data sms from my app (sdk 2.1-update
I am trying to send sms from java application using SMPPSim as SMS gateway
I'm trying to use python and mechanize to send sms from my mobile provider
I was trying to send SMS from within my app. I wrote this piece
I'm trying to send an email in Java but when I read the body
I am trying to send an anonymous object over a web service. Is there
I am trying to send some data from a LINQ query in C# to

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.