Java 用于在近距离内寻找对方的GPS跟踪系统-Android
我正在开发一个android应用程序,它应该能够在一个近距离内找到彼此。我发布了一个问题,描述了所有的要求。请看() 我正在使用一项服务,但我不知道如何定期运行此服务(大约15分钟一次)。而且我也不清楚如何将设备的位置发送到服务器,以及如何获取朋友设备的位置 这是我的尝试 我的xml文件:Java 用于在近距离内寻找对方的GPS跟踪系统-Android,java,android,gps,Java,Android,Gps,我正在开发一个android应用程序,它应该能够在一个近距离内找到彼此。我发布了一个问题,描述了所有的要求。请看() 我正在使用一项服务,但我不知道如何定期运行此服务(大约15分钟一次)。而且我也不清楚如何将设备的位置发送到服务器,以及如何获取朋友设备的位置 这是我的尝试 我的xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schema
<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" />
这是我的MainActivity.java类
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();
}
}
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;
}
}
}
我已将该服务添加到清单文件中
<service android:name=".MyService"></service>
如果有人能帮助我澄清这一点,我将不胜感激
提前感谢。对于该服务,您可以使用或 至于数据的获取/发送,您必须在某个地方安装一台服务器(不确定服务器部分没有得到什么,但您可以在以后要求/提供更多信息)。我对服务器的最佳选择是创建一个web服务(WCF Rest),并通过来自任何Android设备的AsyncTask(JSON)与之通信