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

  • Home
  • SEARCH
  • 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 8034185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:55:51+00:00 2026-06-05T01:55:51+00:00

I’m making an application which runs in background in a mobile. When I send

  • 0

I’m making an application which runs in background in a mobile. When I send a sms with HDPK GPS, the application is supposed to send the GPS co-ordinates of the cell on a fixed number. I receive the GPS co-ordinates on the number but continuously. I have tried everything with removeupdates but all in vain! Please help me sort this issue out. Also when the application listens in the background for the SMS,the GPS and the application too crashes when receives the message, although I get just the toast before the crash. But if the application is running on the screen, it wont crash and continuously sends messages of the co-ordinates.

public class RecActivity extends Activity {
double current_lat, current_lng;
boolean flag=true;
// String provider=LocationManager.GPS_PROVIDER;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
BroadcastReceiver SMSbr = new BroadcastReceiver() {

@Override
public void onReceive(Context context,Intent intent) {

Bundle bundle = intent.getExtras();
if (bundle != null) {

Object[] pdus = (Object[]) bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (messages.length > -1) {
String messagebody=messages[0].getMessageBody();
if(messagebody.toString().matches("HDPK GPS"))
{

LocationManager mlocManager = (LocationManager)getSystemService(RecActivity.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();                   

Toast.makeText(RecActivity.this,"GPS STARTED", Toast.LENGTH_LONG)
                                        .show();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,1, mlocListener);                                 

}

                                                                                           }

}
}

};

IntentFilter SMSfilter = new IntentFilter(SMS_RECEIVED);
this.registerReceiver(SMSbr, SMSfilter);
}

public class MyLocationListener implements LocationListener
{

public void onLocationChanged(Location loc) {
Toast.makeText(RecActivity.this,"GPS WORKING", Toast.LENGTH_LONG).show();
current_lat=loc.getLatitude();
current_lng=loc.getLongitude();
String Text = "My location is: " +

"Latitude = " + current_lat +

"Longitude = " + current_lng;

SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,Text , null, null);
Toast.makeText(RecActivity.this, "SMS SENT", Toast.LENGTH_LONG).show();



}



public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,"GPS Disabled" , null, null);

}

public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,"GPS Enabled" , null, null);

}

 public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub

}

}

}

The Manifest file:

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".RecActivity"
android:label="@string/app_name" >
<intent-filter android:priority="100">
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Here is my code:

package RecSM.Rec.receiveharsh;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class RecActivity extends Activity {
double current_lat, current_lng;
boolean flag=true;
LocationManager mlocManager;
LocationListener mlocListener;
// String provider=LocationManager.GPS_PROVIDER;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
BroadcastReceiver SMSbr = new BroadcastReceiver() {

@Override
public void onReceive(Context context,Intent intent) {

Bundle bundle = intent.getExtras();
if (bundle != null) {

Object[] pdus = (Object[]) bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (messages.length > -1) {


String messagebody=messages[0].getMessageBody();


if(messagebody.toString().matches("HDPK GPS"))
{

LocationManager mlocManager = (LocationManager)getSystemService(RecActivity.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();                   

Toast.makeText(RecActivity.this,"GPS STARTED", Toast.LENGTH_LONG)
                                        .show();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,1, mlocListener);                                 

}


}

}
}

};

IntentFilter SMSfilter = new IntentFilter(SMS_RECEIVED);
this.registerReceiver(SMSbr, SMSfilter);
}

public class MyLocationListener implements LocationListener
{

public void onLocationChanged(Location loc) {


Toast.makeText(RecActivity.this,"GPS WORKING", Toast.LENGTH_LONG)
.show();

current_lat=loc.getLatitude();
current_lng=loc.getLongitude();
String Text = "My location is: " +

"Latitude = " + current_lat +

"Longitude = " + current_lng;

SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,Text , null, null);
Toast.makeText(RecActivity.this, "SMS SENT", Toast.LENGTH_LONG).show();
mlocManager.removeUpdates(mlocListener);


}



public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,"GPS Disabled" , null, null);

}

public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
SmsManager sender=SmsManager.getDefault();
sender.sendTextMessage("9762281814",null,"GPS Enabled" , null, null);

}

public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub

}

}

}
  • 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-05T01:55:53+00:00Added an answer on June 5, 2026 at 1:55 am
    String Text = "My location is: " +
    
    "Latitude = " + current_lat +
    
    "Longitude = " + current_lng;
    
    SmsManager sender=SmsManager.getDefault();
    sender.sendTextMessage("9762281814",null,Text , null, null);
    Toast.makeText(RecActivity.this, "SMS SENT", Toast.LENGTH_LONG).show();
    
    mlocManager.removeUpdates(mlocListener); <<<<<<<<<<<< include this
    

    Code looks fine to me.

    Is you device have GPS hardware in it??.

    Why dont you try fetching location from network provider.
    Make sure you have android.permission.internet in manifest before trying this code.

    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                    .isConnected()
                    || connectivityManager.getNetworkInfo(
                            ConnectivityManager.TYPE_WIFI).isConnected())
            {
                /*Log.d("vipul", "WIFI or GPRS Connected");*/
                if (locationManager
                        .isProviderEnabled(LocationManager.NETWORK_PROVIDER))
                {
                    Constants.CONNECTED = true;
                    /*Log.v("tripSketch", "NETWORK Provider Enabled");*/
                    locationManager.requestLocationUpdates(
                            LocationManager.NETWORK_PROVIDER, 5000, 1, this);
                } else
                {
                    Constants.CONNECTED = false;
                    /*Log.d("vipul",
                            "Please enable Wireless networks in Location Setting!!");*/
                    Toast.makeText(
                            context,
                            "Please enable Wireless networks in Location Setting!!",
                            10000).show();
                }
    
            } else if (locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER))
            {
                Constants.CONNECTED = true;
                /*Log.d("vipul", "GPS Provider Enabled!");*/
                locationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER, 120000, 100, this);
    
            } else
            {
                /*Log.d("vipul", "Neither GPS NOR EDGE/GPRS CONNECTED");*/
                Constants.CONNECTED = false;
                Toast.makeText(
                        context,
                        "Please connect EDGE/GPRS \nAlso Enable Wireless networks in Location Setting!!",
                        10000).show();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
Thanks in advance for your help. I have a need within an application to
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.