Created
January 18, 2013 20:48
-
-
Save anonymous/4568405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Burraq extends MapActivity { | |
long start; | |
long stop; | |
@Override | |
public void onNewIntent(Intent intent) { | |
super.onNewIntent(intent); | |
setIntent(intent); | |
Log.d("MapActivity","Got new Data again"); | |
setMaptoProvidedLocation(); | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_burraq); | |
setMaptoProvidedLocation(); | |
} | |
// Setting Google Map to provided location | |
private void setMaptoProvidedLocation() { | |
//Default position | |
String LON = "33.651686"; | |
String LAT = "73.156333"; | |
if(SmsReceiver.chk==1){ | |
Intent i = getIntent(); | |
LAT = i.getExtras().getString("NewLat"); | |
LON= i.getExtras().getString("NewLon"); | |
} | |
MapView mapView = (MapView) findViewById(R.id.themap); | |
MapController control = mapView.getController(); | |
mapView.setBuiltInZoomControls(true); | |
Touchy t = new Touchy(); | |
List<Overlay> overlayList = mapView.getOverlays(); | |
overlayList.add(t); | |
//Map Animate to new GeoPoints | |
double lat = Double.parseDouble(LON); // latitude | |
double lon = Double.parseDouble(LAT); // longitude | |
GeoPoint geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)); | |
control.animateTo(geoPoint); | |
control.setZoom(100); | |
Toast.makeText(getApplicationContext(), | |
"Your Location is - \nLat: " + lat + "\nLong: " + lon, 0) | |
.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.robot.burraq; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.telephony.SmsMessage; | |
import android.widget.Toast; | |
public class SmsReceiver extends BroadcastReceiver | |
{ | |
// setting global variable. | |
public static String up_lon; | |
public static String up_lat; | |
public static int chk =0; | |
@Override | |
public void onReceive(Context context, Intent intent) | |
{ | |
//---get the SMS message passed in--- | |
Bundle bundle = intent.getExtras(); | |
SmsMessage[] msgs = null; | |
String str = ""; | |
String str2 = ""; | |
//fetching message string | |
if (bundle != null) | |
{ | |
//---retrieve the SMS message received--- | |
Object[] pdus = (Object[]) bundle.get("pdus"); | |
msgs = new SmsMessage[pdus.length]; | |
String sender_num = null; | |
for (int i=0; i<msgs.length; i++){ | |
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); | |
// str += "SMS from " + msgs[i].getOriginatingAddress(); | |
// str += " :"; | |
str = msgs[i].getMessageBody().toString(); | |
// str += "\n"; | |
sender_num = msgs[i].getOriginatingAddress(); | |
} | |
//Divide message string to 2 parts longitude and latitude by detection "," | |
int flag =0; | |
str2 =str.substring(3,4); | |
up_lon = ""; | |
up_lat = ""; | |
for(int j=0; j<str.length();j++) | |
{ | |
str2 =str.substring(j,j+1); | |
if(flag == 1) | |
{ | |
up_lat += str2; | |
} | |
if(str2.equals(",")) | |
{ | |
flag = 1; | |
} | |
if(flag == 0) | |
{ | |
up_lon += str2; | |
} | |
} | |
chk=1; | |
//New Location fetched | |
Toast.makeText(context,up_lat + up_lon , Toast.LENGTH_SHORT).show(); | |
Intent i = new Intent(); | |
i.putExtra("NewLat", up_lat); | |
i.putExtra("NewLon", up_lon); | |
} | |
} | |
} |
Its good to know that your code is working now...
Now , you can handle some things like -----
- Handle map display for frequent sms ( like map is not loaded and you get new sms again )
- Sms authentication and validation .
- Overlay zoom in and zoom out ...so ..It can feel user that location has been changed ...
One more thing...please don't forget to vote up answer in stack overflow , so It would be useful in future for other guys like you...:)
- Even apart from SMS ,you can use other cheaper ways ...like GCM ( Push notification )...
anyways ..its your choice... :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where are you starting Burraq activity in SmsReceiver ?
Please modify the code as per bellow -
//New Location fetched
Toast.makeText(context,up_lat + up_lon , Toast.LENGTH_SHORT).show();
final Intent intent = new Intent(context, Burraq.class);
i.putExtra("NewLat", up_lat);
i.putExtra("NewLon", up_lon);
context.startActivity(intent); // I can not find this in you code ...
Now , First time , if you get sms , It would start Map activity...
Second time , If Map activity is in forground and still you get sms in background ,
It would again restart the activity...!!