发送短信时,移动设备出来的特定区域 [英] Send SMS when mobile device comes out of a specific area

查看:166
本文介绍了发送短信时,移动设备出来的特定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Android应用程序这 使用GPS和商店1.Tracks电话的位置是一个文件 2.发送一个短信到一个号码,当手机离开指定区域。

I am building a android application which 1.Tracks phones location using GPS and stores it a file 2. It sends a SMS to a number when the phone goes out of a specified area.

我已经实现了第一个使用commonsware的 Locationpoller ,但我想知道如何实现第二个。

I've implemented the first one using commonsware's Locationpoller but I want to know how to implement the second one.

我如何选择在地图上的特定区域? 如何创建一个报警(或事件)当手机离开该区域的?

How do I select a specific area on Map ? How to create a alarm(or event) when phone is out of that area ?

推荐答案

要落实

它发送一个短信到一个号码,当手机离开指定区域。

您可以决定发言权的例如半径5公里相对于在地图上的当前位置。现在你拥有了它的当前位置存储在共享preference。实施的服务。使用位置监听器。因此,当<一href="http://developer.android.com/reference/android/location/LocationListener.html#onLocationChanged%28android.location.Location%29"相对=nofollow> onLocationChanged()被调用时,你<一个href="http://developer.android.com/reference/android/location/Location.html#distanceBetween%28double,%20double,%20double,%20double,%20float%5B%5D%29"相对=nofollow>可以计算存储在共享preference新的位置和位置之间的距离。如果超过你的决定的区域,然后发送短信。

you can decide the radius of say for e.g. 5km relative to your current location on map. now you have the current location store it in shared preference. implement The Service. Use Location Listener. so when the onLocationChanged() is called, you can calculate the distance between the new location and location stored in shared preference. if it exceeds your decided area, then send the sms.

也许它的工作原理。

修改:既然你的男人拒绝张贴任何code,我发现了一些。以下是如何发个短信编程,与Android 2.2及以上,如果你有麻烦搞清楚你的​​用户,我会写一些东西来让您过婴儿床,以及:

EDIT: since your man refuses to post any code, I found some. Here's how to send a text message programmatically, with Android 2.2 and above, if you have trouble figuring out where your user is, I'll write something up for you to crib off of as well:

import android.app.Activity;
import android.os.Bundle;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
    Button btnSendSMS;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
       btnSendSMS.setOnClickListener(new 
       View.OnClickListener() {
           public void onClick(View v) {
        sendSMS(System.getProperty("numberToSendTo"), "Hello my friends!");
           }
       });
    }
    //---sends an SMS message to another device---
    private void sendSMS(String phoneNumber, String message) {
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    }
   }                       

这篇关于发送短信时,移动设备出来的特定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆