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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:39+00:00 2026-05-26T18:05:39+00:00

I have problem with my Android application. I need an application that will send

  • 0

I have problem with my Android application. I need an application that will send in background GPS location every 10 minutes to the server (here I have WCF service that work). Application needs to send data even if it is closed. So I created a service (for test purposes) that sends to me time on server. But when I insert my code for getting GPS location in my service everything fails (stopped unexpectedly).

I have reed that you need to put some receiver or something but nothing so far works. So I will be very pleased if someone can help me.

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.biromatik.GPS"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:name=".MyApplication" >
    <service
        android:enabled="true"
        android:name=".MonitorService" >
    </service>
    <receiver
        android:enabled="true"
        android:name=".LocationReceiver" >
        <intent-filter >
            <action android:name="com.biromatik.intent.action.LOCATION" />
        </intent-filter>
    </receiver>
</application>


     <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />




</manifest>
  • 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-26T18:05:39+00:00Added an answer on May 26, 2026 at 6:05 pm

    I’ve done this in my app to do the same thing you asked.

    In my service I added this:

    @Override
    public void onStart(Intent intent, int startId) {
    
        super.onStart(intent, startId);
        addLocationListener();
    }
    
    private void addLocationListener()
    {
        triggerService = new Thread(new Runnable(){
            public void run(){
                try{
                    Looper.prepare();//Initialise the current thread as a looper.
                    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    
                    Criteria c = new Criteria();
                    c.setAccuracy(Criteria.ACCURACY_COARSE);
    
                    final String PROVIDER = lm.getBestProvider(c, true);
    
                    MyLocationListener myLocationListener = new MyLocationListener();
                    lm.requestLocationUpdates(PROVIDER, 600000, 0, myLocationListener);
                    Log.d("LOC_SERVICE", "Service RUNNING!");
                    Looper.loop();
                }catch(Exception ex){
                    ex.printStackTrace();
                }
            }
        }, "LocationThread");
        triggerService.start();
    }
    
    public static void updateLocation(Location location)
    {
        Context appCtx = MyApplication.getAppContext();
    
        double latitude, longitude;
    
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    
        Intent filterRes = new Intent();
        filterRes.setAction("xxx.yyy.intent.action.LOCATION");
        filterRes.putExtra("latitude", latitude);
        filterRes.putExtra("longitude", longitude);
        appCtx.sendBroadcast(filterRes);
    }
    
    
    class MyLocationListener implements LocationListener
    {
    
        @Override
        public void onLocationChanged(Location location)
        {
            updateLocation(location);
        }
    }
    

    NOTE: See that I use MyApplication.getAppContext(); that’s because I’m using my own Application class to add the context.
    And then I have a BroadcastReceiver with this:

    public class LocationReceiver extends BroadcastReceiver {
    
        double latitude, longitude;
    
        @Override
        public void onReceive(final Context context, final Intent calledIntent)
        {
            Log.d("LOC_RECEIVER", "Location RECEIVED!");
    
            latitude = calledIntent.getDoubleExtra("latitude", -1);
            longitude = calledIntent.getDoubleExtra("longitude", -1);
    
            updateRemote(latitude, longitude);
    
        }
    
        private void updateRemote(final double latitude, final double longitude )
        {
            //HERE YOU CAN PUT YOUR ASYNCTASK TO UPDATE THE LOCATION ON YOUR SERVER
        }
    }
    

    the Application class:

    public class MyApplication extends Application {
    
    
        private static Context context;
    
        /* (non-Javadoc)
         * @see android.app.Application#onCreate()
         */
        @Override
        public void onCreate() {            
            MyApplication.context=getApplicationContext();
        }
    
        public static Context getAppContext() {
            return MyApplication.context;
        }
    }
    

    Also in your manifest you need to add both:

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:name=".MyApplication" >
    
        //YOUR ACTIVITIES HERE...
    
        <service
            android:enabled="true"
            android:name=".LocationService" >
        </service>
    
        <receiver
            android:enabled="true"
            android:name=".LocationReceiver" >
            <intent-filter >
                <action android:name="xxx.yyy.intent.action.LOCATION" />
            </intent-filter>
        </receiver>
    </application>
    

    Method to detect if the service is running I do this on my first Activity:

    /**
     * Check location service.
     */
    private void checkLocationService()
    {
        Log.d("CHECK_SERVICE", "Service running: " + (settings.getBoolean("locationService", false)?"YES":"NO"));
    
        if(settings.getBoolean("locationService", false))
            return;
    
        Intent mServiceIntent = new Intent(this, LocationService.class);
        startService(mServiceIntent);
    }
    

    Obviously you need to control the SharedPreferences (settings) to set the locationService variable to true/false if the service is running (onStart) or not (onDestroy).

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

Sidebar

Related Questions

I have an interesting problem being reported to me from an android application I
I have been given the tasks of speccing a mobile application, which will need
I have an Android application with a main activity that is the tabhost. I'm
In my Android application I need to have a black action bar and my
I have an Android application that generates some HTML which is rendered locally, in
n00b here (first Android project). I have been given a custom video codec that
I have android app that talks to server and syncs some data int SQLite
I have been trying to create a simple application that will let the user
I am writing an android application and I need to have two classes use
In an Android application I need to add a view to my RelativeLayout that

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.