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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:36:57+00:00 2026-06-12T12:36:57+00:00

I am trying to send battery information in regular intervals to my server.I already

  • 0

I am trying to send battery information in regular intervals to my server.I already tested the webservice code and it is working fine without using Android Services but throws exception when I am trying to call webservice method inside runnable in Service.

Though its working fine when I am trying to print Toast inside runnable in my Android Service.

 package com.services;

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;

    import android.app.Service;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Handler;
    import android.os.IBinder;
    import android.widget.Toast;

    public class BackService extends Service {
        private int m_interval = 20000; // 5 seconds by default, can be changed later
        private Handler m_handler;
        int  Level;

         private static final String SOAP_ACTION = "http://xy.xy/insertfeedback";
            private static final String METHOD_NAME = "insertfeedback";
            private static final String NAMESPACE = "http://xy.xy/";
            private static final String URL = "http://192.168.9.2:8080/WebApplication2/NewWebServiceService?WSDL";
            SoapObject request;
            SoapSerializationEnvelope envelope;
            HttpTransportSE ht;

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

       @Override
       public void onCreate() {

             Toast.makeText(getApplicationContext(), "Service Created", Toast.LENGTH_SHORT).show();
             request= new SoapObject(NAMESPACE, METHOD_NAME);       
             envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             ht = new HttpTransportSE(URL);
       }

       @Override
       public void onDestroy() {
          //code to execute when the service is shutting down
       }

       @Override
       public void onStart(Intent intent, int startid) {
             registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

         Toast.makeText(getApplicationContext(), "Service Stared", Toast.LENGTH_SHORT).show();
         m_handler = new Handler();
         m_statusChecker.run();
       }

       Runnable m_statusChecker = new Runnable()
       {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(), ""+ Level, Toast.LENGTH_SHORT).show();
                BatteryService();
                 //updateStatus(); //this function can change value of m_interval.
                 m_handler.postDelayed(m_statusChecker, m_interval);
            }
       };


       private final BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
           @Override
           public void onReceive(Context arg0, Intent intent) {
            Level = intent.getIntExtra("level", 0);
             //Toast.makeText(getApplicationContext(), ""+Level+"%", Toast.LENGTH_SHORT).show();

           }
           };


          public void BatteryService()
          {

              request.addPropertyIfValue("value",50);
              envelope.setOutputSoapObject(request);


              try
              {
                  ht.call(SOAP_ACTION, envelope);
                  final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
                  final String str = response.toString();
                  Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
              }
               catch (Exception e) {
                   Toast.makeText(getApplicationContext(),"Exception", Toast.LENGTH_LONG).show();

              }
          }
    }
  • 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-12T12:36:58+00:00Added an answer on June 12, 2026 at 12:36 pm

    What kind of the Exception do you meet? You should post the Log too. It will help a lot find out your problem

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

Sidebar

Related Questions

I´m trying to send an email through gmail using this code: MailMessage msg =
am trying to send an email using the following code $this->load->library('email', $config); $this->email->from('leena.nasir552@gmail.com'); $this->email->to('leena.nasir@morgan.com');
trying to send Arabic text from android to PHP file using the code below
am trying send an array to php file using $_POST ,still always getting an
Trying to send a complex type between two systems that have the same code
I`m trying to send e-mail via c# and use the following code: public static
I am trying to send emails from smtps (secure smtp) using Indy and the
Trying to send POST request on click event using jQuery with no luck. Here
I´m trying to send a image through tcp to a server, firts getting the
I am trying to send request to server in every 2 seconds in a

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.