package com.acmetensortoys.android.teled.Service;
+import android.Manifest;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.Context;
+import android.location.Location;
+import android.location.LocationManager;
import android.net.Uri;
+import android.telephony.SmsManager;
import android.util.Log;
/**
if (intent != null) {
final String action = intent.getAction();
if (ACTION_TEST.equals(action)) {
- Log.d("EphemeralTeleDService", "Test action: " + intent.toString() + " eb=" + intent.getExtras().toString());
+ Log.d("EphemeralTeleDService", "Test action: " + intent.toString());
+ if(intent.getExtras() != null) {
+ Log.d("EphemeralTeleDService", " ... has extras=" + intent.getExtras().toString());
+ }
} else if (ACTION_SEND_LOCATION_SMS.equals(action)) {
- // final String param1 = intent.getStringExtra(EXTRA_PARAM1);
- handleActionSendLocationSMS(intent);
+ Uri to = intent.getData();
+
+ LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+ this.enforceCallingOrSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION,
+ "Missing location permission");
+ Location l = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
+
+ SmsManager sm = SmsManager.getDefault();
+ // XXX Hook send and delivery messages
+ sm.sendTextMessage(to.getSchemeSpecificPart(), null, "locn rep : " + l.toString(), null, null);
+
} /* else if (ACTION_BAZ.equals(action)) {
final String param1 = intent.getStringExtra(EXTRA_PARAM1);
final String param2 = intent.getStringExtra(EXTRA_PARAM2);
} */
}
}
-
- /**
- * Handle action Foo in the provided background thread with the provided
- * parameters.
- */
- private void handleActionSendLocationSMS(Intent i) {
- // TODO: Handle action Foo
- throw new UnsupportedOperationException("Not yet implemented");
- }
}
import android.location.LocationListener;
import android.location.LocationManager;
-public abstract class PositionReporting
+public class PositionReporting
{
public PositionReporting(Context ctx, LocationListener ll) {
LocationManager lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
package com.acmetensortoys.android.teled.UI;
import android.app.Activity;
+import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.util.Log;
import com.acmetensortoys.android.teled.R;
+import com.acmetensortoys.android.teled.Service.EphemeralTeleDService;
public class FragPrefs
extends PreferenceFragment {
public boolean onPreferenceClick(Preference _p) {
Intent conPik = new Intent(
Intent.ACTION_PICK,
- ContactsContract.Contacts.CONTENT_URI);
+ ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(conPik, REQID_SMS_PICK);
return true;
}
*/
}
+ static final String[] phone_Uri_projection = { ContactsContract.CommonDataKinds.Phone.NUMBER };
+
@Override
public void onActivityResult(int req, int res, Intent i) {
if(req == REQID_SMS_PICK && res == Activity.RESULT_OK) {
- Log.d("FragPrefs", i.toString());
+ Log.d("FragPrefs", "SMS_PICK " + i.toString());
+
+ Cursor c = getActivity().getContentResolver()
+ .query(i.getData(), phone_Uri_projection, null, null, null );
+ if (c != null) {
+ c.moveToFirst();
+ String number = c.getString(c.getColumnIndex(phone_Uri_projection[0]));
+ c.close();
+
+ Log.d("FragPrefs", " ... which is to say: " + number);
+
+ Uri x = Uri.fromParts("smsto", number, "");
+ PendingIntent pi = EphemeralTeleDService.pendingSendLocationSMS(getActivity(), x);
+ try {
+ pi.send();
+ } catch (PendingIntent.CanceledException ce) {
+ Log.d("FragPrefs", "... pi cancelled?");
+ }
+ } else {
+ Log.d("FragPrefs", " ... null cursor?");
+ }
}
}
}
import android.content.ServiceConnection;
import android.content.ComponentName;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.CancellationSignal;
import android.os.IBinder;
private final static int PERM_REQ_IX_RECV_SMS = 1;
private final static int PERM_REQ_IX_FINE_LOC = 2;
+ private final static int PERM_REQ_IX_EVERYTHING = 3;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onStart();
bindService(new Intent(this, TeleDService.class), tdisSC,
Context.BIND_AUTO_CREATE | Context.BIND_ABOVE_CLIENT);
+
+ Log.d("Main", "Requesting permission?");
+ requestPermissions(
+ new String[]{
+ Manifest.permission.ACCESS_FINE_LOCATION,
+ Manifest.permission.RECEIVE_SMS,
+ Manifest.permission.SEND_SMS},
+ PERM_REQ_IX_EVERYTHING);
}
@Override