1

I am attempting to create an app that acts passivly in the background. What I want it to do is keep track of the speed (interchangeable between MPH and KmPH based on the user's wishes) passively. When a text message comes to the device, I want it to check the speed and if it's below the user defined threshhold, I want it to send the SMS to the default app. If over the threshhold, I want it to send an automatic message back to the sender.

Currently I have 2 activites because I cannot extend both Activity and BroadcastReceiver.

My first question is.. how to I keep track of the speed passively... My second question is.. how do I pass the speed to the SMS activity when a SMS is received?

Here is my GPSActivity

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

    }

}

Here is my SMSActivity

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);
        }
}
jpgerb
  • 1,043
  • 1
  • 9
  • 36

0 Answers0