public
anonymous / Burraq(main)
Created

  • Download Gist
Burraq(main)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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();
 
}
}
SmsReceiver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
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);
}
}
}

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...!!

Its good to know that your code is working now...
Now , you can handle some things like -----
1) Handle map display for frequent sms ( like map is not loaded and you get new sms again )
2) Sms authentication and validation .
3) 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...:)

4) Even apart from SMS ,you can use other cheaper ways ...like GCM ( Push notification )...

anyways ..its your choice... :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.