2011-12-31 89 views
-3

可能重复纬度,经度和地址:
How to retrieve the GPS location via SMS如何让机器人

我提出是要像这样一个Android应用程序: 当用户键入一个包含例如“findmyphone”或类似的东西(它不会响应其他正常文本消息)的短信给运行该应用程序的电话,应用程序将自动响应该号码的纬度,经度和地址正在运行应用程序的电话。

我还需要一个按钮来测试它。一旦用户按下“测试”按钮,纬度,经度和地址将出现在2个文本框中,纬度和经度为1,地址在另一个文本框中。非常感谢!这是我到目前为止有:

import java.io.IOException; 
import java.util.List; 
import java.util.Locale; 

import android.app.Activity; 
import android.content.Context; 
import android.location.Address; 
import android.location.Geocoder; 
import android.location.Location; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 

public class FindAndroidActivity extends Activity implements OnClickListener { 
/** Called when the activity is first created. */ 
Button Nextbutton1, Nextbutton2, TestLocationService; 
TextView Cordinates, Adress, FindAndroid; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Nextbutton1 = (Button)findViewById(R.id.Nextbutton1); 
    Nextbutton1.setOnClickListener(this); 
} 
public void onClick(View src) { 
    switch (src.getId()) { 
    case R.id.Nextbutton1: 
     setContentView(R.layout.setup); 
     Nextbutton2 = (Button)findViewById(R.id.Nextbutton2); 
     Nextbutton2.setOnClickListener(this); 
     TestLocationService = (Button)findViewById(R.id.TestLocationService); 
     TestLocationService.setOnClickListener(this); 
     break; 
    case R.id.Nextbutton2: 
     setContentView(R.layout.main); 
     break; 
    case R.id.TestLocationService: 
     break; 
    } 
} 
    public Address getAddressForLocation(Context context, Location location) throws IOException { 

     if (location == null) { 
      return null; 
     } 
     double latitude = location.getLatitude(); 
     double longitude = location.getLongitude(); 
     int maxResults = 1; 

     Geocoder gc = new Geocoder(context, Locale.getDefault()); 
     List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults); 

     if (addresses.size() == 1) { 
      return addresses.get(0); 
     } else { 
      return null; 
     } 
} 

}

+4

“我怎样才能做到这一点尽可能简单?”你应该付钱给你这样做...这是最简单的解决方案... – Selvin 2011-12-31 14:51:25

+1

你的错误或问题是什么?任何人都可以复制和粘贴烟幕的代码。 – Robert 2011-12-31 15:52:59

+0

我所需要的一切就是一旦收到短信,以及如何获得经纬度和地址,就会发生一些事情。所以,如果我失去了我的手机,然后我借给他人的电话,并发送短信到该手机,其中包含:“PhoneLocate”,它响应该手机的地址和坐标。但是,只有当这个词是PhoneLocate或者我指定的那个。我已经在android市场上有了一个应用程序,但是它是由应用程序发明者制作的,我想在eclipse中制作,但是在位置上没有太多经验。应用程序名称是:PhoneLocator。 – MySoftware 2011-12-31 16:17:32

回答

0

我不会放弃任何东西的详细说明,因为你可以做一个谷歌搜索或搜索StackOverflow上为您最需要的信息。

要获取位置,请使用LocationManager并调用requestLocationUpdates。有很多教程解释如何做到这一点。

要接收短信,你需要在你的清单,如下列宣布BroadcastReceiver

<receiver android:name=".SmsReceiver"> 
        <intent-filter> 
         <action android:name="android.provider.Telephony.SMS_RECEIVED"/> 
        </intent-filter> 
       </receiver> 

在这个rec​​eivery你可以使用SmsMessage类来获得从SMS必要的信息。

然后发回短信,您将使用SmsManager并调用sendTextMessage

但是
你真的需要自己完成这项工作。同样值得注意的是,市场上已经有TON的手机定位器应用程序,所以这可能不是一个值得你去制作的应用程序。

而且,您可以搜索stackoverflow或Google以了解如何处理您需要的每件事。

如果你没有做任何实际的Android编程(因为你说你使用的应用程序的发明者),那么你需要看看Developer's Guide