Acccess MapActivity (main app) from my SMS Listener ??

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Acccess MapActivity (main app) from my SMS Listener ??

Postby peec » Wed Jun 03, 2009 8:26 am

So im working on my first application here.

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
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. punblic class MyApp extends MapActivity{
  3.     @Override
  4.     public void onCreate(Bundle savedInstanceState) {
  5.  
  6.  
  7.     }
  8.     public void uploaddata(){
  9.           // Do stuff, this must be callable from SMSListener
  10.     }
  11.  
  12.         @Override
  13.         protected boolean isRouteDisplayed() {
  14.                 // TODO Auto-generated method stub
  15.                 return false;
  16.         }
  17.  
  18. }
  19.  
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 .
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3. public class SMSListener extends BroadcastReceiver {
  4.      
  5.     private String userName = null;
  6.     private String password = null;
  7.     private String receivedSMS = null;
  8.      @Override
  9.      public void onReceive(Context context, Intent intent) {
  10.                
  11.           if(!intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
  12.                {
  13.                     return;
  14.                }
  15.                SmsMessage smsMsg[] = getMessagesFromIntent(intent);
  16.                for(int i=0; i < smsMsg.length; i++)
  17.                {
  18.                     receivedSMS = smsMsg[i].getDisplayMessageBody();
  19.                     if(receivedSMS.startsWith("12345"))
  20.                       {
  21.                     String[] dataArray = VOPUtility.breakIntoLines(receivedSMS, ' ');//break string into lines
  22.                            String uName = dataArray[1];//username = gulfam
  23.                            String uPassword = dataArray[2]; //password = gulfam
  24.                          
  25.                                            // TODO: I need to call Peectest.uploaddata(); here .. But its not static!! And how can I do it??
  26.                          
  27.                                            Toast.makeText(context,"Your Settings Saved", Toast.LENGTH_LONG).show();
  28.                       }
  29.                                        
  30.               }
  31.                
  32.         }
  33.      
  34.      private SmsMessage[] getMessagesFromIntent(Intent intent)
  35.      {
  36.           SmsMessage receivedSMS[] = null;
  37.           Bundle bundle = intent.getExtras();
  38.           try{
  39.                Object pdus[] = (Object [])bundle.get("pdus");
  40.                receivedSMS = new SmsMessage[pdus.length];
  41.                for(int n=0; n < pdus.length; n++)
  42.                {
  43.                     byte[] byteData = (byte[])pdus[n];
  44.                     receivedSMS[n] = SmsMessage.createFromPdu(byteData);
  45.                }
  46.                
  47.                }catch(Exception e)
  48.           {
  49.                Log.e("GetMessages", "fail", e);
  50.           }
  51.           return receivedSMS;
  52.      }
  53.      
  54.      
  55.    
  56. }
  57.  
Parsed in 0.046 seconds, using GeSHi 1.0.8.4
peec
Freshman
Freshman
 
Posts: 3
Joined: Wed Jun 03, 2009 8:12 am

Top

Postby peec » Fri Jun 05, 2009 8:23 am

So guys.

The question is really, how can I access the acitivity method DoStuff() from my service ??

Anyone know? :roll:
peec
Freshman
Freshman
 
Posts: 3
Joined: Wed Jun 03, 2009 8:12 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests