I'm making an android application. in IncomingSMS.java there's this string called the senderNum. senderNum is generated when a message is received and senderNum string is the sender of the message. i want to call senderNum to another class. it is said that i need to return the value of the string. but i don't know how. Shown below are part of the codes.
IncomingSMS.java
public class IncomingSms extends BroadcastReceiver { private static final byte TARGET_PIN_2 = 0x2; private String message = ""; private static boolean ledstate = false; // Get the object of SmsManager final SmsManager sms = SmsManager.getDefault(); public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage .createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage .getDisplayOriginatingAddress(); String senderNum = phoneNumber; message = currentMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message); int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, "senderNum: "+ senderNum + ", message: " + message, duration); toast.show(); // call led here toggleLed(); } // end for loop } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
below is the class where i want to call the senderNum string
MainActivity.java
public void sendLOCKED() { SmsManager smsManager = SmsManager.getDefault(); // i want to call the senderNum below smsManager.sendTextMessage("senderNum", null, "LOCKED", null, null); } public void sendUNLOCKED() { SmsManager smsManager = SmsManager.getDefault(); // i want to call the senderNum below smsManager.sendTextMessage("senderNum", null, "UNLOCKED", null, null); }