Android 如何组合GPS和SMS应用程序?
我正在尝试创建一个在后台被动运行的应用程序。我想要它做的是被动地根据用户的意愿跟踪每小时和每公里的速度。当手机收到短信时,我希望它检查速度,如果低于用户定义的阈值,我希望它将短信发送到默认应用程序。如果超过阈值,我希望它自动将消息发送回发送者 目前我有2个活动,因为我无法同时扩展活动和广播接收器 我的第一个问题是。。如何被动地跟踪速度。。。 我的第二个问题是。。收到短信时,如何将速度传递给短信活动 这是我的活动Android 如何组合GPS和SMS应用程序?,android,gps,sms,passive-mode,Android,Gps,Sms,Passive Mode,我正在尝试创建一个在后台被动运行的应用程序。我想要它做的是被动地根据用户的意愿跟踪每小时和每公里的速度。当手机收到短信时,我希望它检查速度,如果低于用户定义的阈值,我希望它将短信发送到默认应用程序。如果超过阈值,我希望它自动将消息发送回发送者 目前我有2个活动,因为我无法同时扩展活动和广播接收器 我的第一个问题是。。如何被动地跟踪速度。。。 我的第二个问题是。。收到短信时,如何将速度传递给短信活动 这是我的活动 package biz.midl.drivereply; import andro
package biz.midl.drivereply;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity implements LocationListener {
String lsms;
String prefName = "chaosgpsreply";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
this.onLocationChanged(null);
}
@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 onLocationChanged(Location location) {
TextView tv = (TextView) findViewById(R.id.textView1);
if (location==null)
{
tv.setText("-.- m/s");
}
else
{
float nCurrentSpeed = location.getSpeed();
tv.setText("" + nCurrentSpeed + " m/s");
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
这是我的活动
package biz.midl.drivereply;
import java.util.Timer;
import java.util.TimerTask;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
public class SMSportion extends BroadcastReceiver {
String lsms;
String prefName = "chaosgpsreply";
static Timer timer1 = new Timer();
static long delay = 30000;
static TimerTask tt1;
@Override
public void onReceive(Context context, Intent intent) {
String phoneNumber=null, messageText=null;
String textMessage = "I can't come to the phone right now, be back soon";
//---gather up all the necessary user input---
SmsManager sms = SmsManager.getDefault();
try
{
sms.sendTextMessage(phoneNumber, null, messageText, null, null);
}
catch(IllegalArgumentException e)
{
}
//timer(); //this will be integrated in later - ignore this
sendSMS(phoneNumber, textMessage);
}
public void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}
如果有人有任何建议,我仍然在寻找关于这个问题的答案。