52118

GPS tracking system for find each other in a close area - Android

Question:

I am developing an android application which should has the capability of finding each other in a close area. I've posted a question which describes all the requirements. Please look at (<a href="https://stackoverflow.com/questions/20321620/android-gps-tracking-system-for-find-each-other-in-a-close-area" rel="nofollow">Android : GPS tracking system for find each other in a close area</a>)

I am using a service but I don't know how to run this service periodically (once in 15 mins or so ). And also I have no clear idea about how to send the location of devices to the server and how to fetch locations of friend's device.

Here is my attempt.

My xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_alignParentRight="true" android:onClick="stopNewService" android:text="Stop Service" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="23dp" android:onClick="startNewService" android:text="Start Service" />

This is my <strong>MyService.java</strong> class

package com.example.service; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class MyService extends Service { @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG) .show(); } @Override public void onStart(Intent intent, int startId) { // For time consuming an long tasks you can launch a new thread here... Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show(); } @Override public void onDestroy() { Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show(); } }

And here is my <strong>MainActivity.java</strong> class

package com.example.service; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity implements View.OnClickListener { private Button bStart, bStop; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } // Start the service public void startNewService(View view) { startService(new Intent(this, MyService.class)); } // Stop the service public void stopNewService(View view) { stopService(new Intent(this, MyService.class)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.button1: startNewService(v); break; case R.id.button2: stopNewService(v); break; default: break; } } }

I've added the service into manifest file.

<service android:name=".MyService"></service>

I would be much thankful if anyone please be so kind enough to help me to clarify this.

Thanks in advance.

Answer1:

For the service, you can use an <a href="http://developer.android.com/reference/android/app/AlarmManager.html" rel="nofollow">AlarmManager</a> or a <a href="http://developer.android.com/reference/android/os/Handler.html" rel="nofollow">Handler</a>.

As for the fetching/sending of data, you have to have a server located somewhere (not sure what you are not getting with the server part, but you can ask for/give more information afterwards). My best bet with the server is creating a web service (WCF Rest) and communicating with it via AsyncTask (JSON) from any Android device.

Recommend

  • How can I make multiple activities be in one activity changing only strings?
  • Can i use css like as javascript?
  • Vertically stack an array of buttons using auto layout VFL
  • Different layers in Corona/Lua
  • Robotium & system dialogs
  • Delete an item in a listbox with a button, in wpf MVVM
  • Tkinter button 'not defined' when ran
  • I can't show LinearLayout at bottom to scroll view
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • Android Custom dialog inflating from layout - alignment issue
  • Align Excel cell to center VB - xlCenter is not declared
  • EditText ignores the ImeActionLabel
  • Javascript (MVC) load image (byte array) from database
  • Gray line inside cardview :)?
  • Send data from edittext to listview
  • countdown bar android example
  • Jquery Mobile pageLoading() Method how does it work?
  • Simulate click Geckofx vb,net
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Android fill_parent issue
  • jQuery show() function is not executed in Safari if submit handler returns true
  • Align navbar back button on right side
  • HTML download movie download link
  • Modifying destination and filename of gulp-svg-sprite
  • How to handle AllServersUnavailable Exception
  • How to model a transition system with SPIN
  • VBA Convert delimiter text file to Excel
  • ORA-29908: missing primary invocation for ancillary operator
  • jquery mobile loadPage not working
  • How to disable jQuery.jplayer autoplay?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically