I have gone quite far, the app is working and ATM im trying to implement SMS feature so i get a "command" from SMS and then it will do stuff in the MapActivity Class.
Look at the following example so you can see what I mean.
MapApp.java
Using java Syntax Highlighting
- punblic class MyApp extends MapActivity{
- @Override
- public void onCreate(Bundle savedInstanceState) {
- }
- public void uploaddata(){
- // Do stuff, this must be callable from SMSListener
- }
- @Override
- protected boolean isRouteDisplayed() {
- // TODO Auto-generated method stub
- return false;
- }
- }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
SMSListener.java
Look @ " // TODO: I need to call Peectest.uploadData(); here .. But its not static!! And how can I do it??" And you will catch my drift.. I really need to call MyApp's instance, but how? "this." does not work .
Using java Syntax Highlighting
- public class SMSListener extends BroadcastReceiver {
- private String userName = null;
- private String password = null;
- private String receivedSMS = null;
- @Override
- public void onReceive(Context context, Intent intent) {
- if(!intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
- {
- return;
- }
- SmsMessage smsMsg[] = getMessagesFromIntent(intent);
- for(int i=0; i < smsMsg.length; i++)
- {
- receivedSMS = smsMsg[i].getDisplayMessageBody();
- if(receivedSMS.startsWith("12345"))
- {
- String[] dataArray = VOPUtility.breakIntoLines(receivedSMS, ' ');//break string into lines
- String uName = dataArray[1];//username = gulfam
- String uPassword = dataArray[2]; //password = gulfam
- // TODO: I need to call Peectest.uploaddata(); here .. But its not static!! And how can I do it??
- Toast.makeText(context,"Your Settings Saved", Toast.LENGTH_LONG).show();
- }
- }
- }
- private SmsMessage[] getMessagesFromIntent(Intent intent)
- {
- SmsMessage receivedSMS[] = null;
- Bundle bundle = intent.getExtras();
- try{
- Object pdus[] = (Object [])bundle.get("pdus");
- receivedSMS = new SmsMessage[pdus.length];
- for(int n=0; n < pdus.length; n++)
- {
- byte[] byteData = (byte[])pdus[n];
- receivedSMS[n] = SmsMessage.createFromPdu(byteData);
- }
- }catch(Exception e)
- {
- Log.e("GetMessages", "fail", e);
- }
- return receivedSMS;
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

