public class SMSNotificationListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Here you can extract the intent extra ( lat , longs )
// Even you can check some message code to identify valid message
// Can call some different MapDisplayActivity with lat , longs
// in Intent.putExtra(...)
}
}
AndroidManifest にレシーバーを追加します -
<receiver android:name=".SMSNotificationListener">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</receiver>
MapDisplayActivity で ---
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapview);
setMaptoProvidedLocation();
}
/**
* Setting Google Map to provided location
*/
private void setMaptoProvidedLocation() {
Intent intent = getIntent();
LAT = intent.getIntExtra(DisplayActivity.LAT, DisplayActivity.DEF_LAT);
LNG = intent.getIntExtra(DisplayActivity.LNG, DisplayActivity.DEF_LNG);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapController = mapView.getController();
mapController.setZoom(ZOOM_LEVEL - ZOOM_LEVEL / 2);
GeoPoint vehicleLocation = new GeoPoint(LAT, LNG);
mapController.animateTo(vehicleLocation);
// You can also add map overlays ...
}
//If MapDisplayActivity is in forground and we want to update the new location
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
Log.d("MapActivity","Got new Data again");
setMaptoProvidedLocation(false);
}