0

I'm trying to modify the Android source in the following way: When the user sends an SMS, a popup window (in the form of a new activity) is displayed from within SmSManager class asking if the user is sure that he wants to send the SMS. If he clicks OK the message is sent. Otherwise it's not. I have successfully displayed the popup window but now I'm stuck on the onClick event. How can I pass data from the activity to the SmSManager class?

Edit: Code as requested

In SmsManager.sendTextMessage():

Intent smsIntent = new Intent(Intent.ACTION_MAIN, null);
smsIntent.setComponent(new ComponentName("com.package", "com.package.MyActivity"));
smsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityThread.currentApplication().getApplicationContext().startActivity(smsIntent);

In MyActivity

    final Button btn_ok = (Button) findViewById(R.id.btn_ok);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // What do I need to write here?
            finish();
        }
    });
5
  • Please share some code... Oct 7, 2014 at 13:07
  • what was in SmsManager before you added you piece of code?
    – njzk2
    Oct 7, 2014 at 13:16
  • SmsManager is a built-in class of Android responsible for sending SMS and data messages. I added my code in the sendTextMessage() function
    – Warmaster
    Oct 7, 2014 at 13:19
  • @Warmaster: my point exactly. in the original sendTextMessage function is the code for actually sending the sms. This is the code you want to use to send the SMS. Or, add a new function in SmsManager to do that part for you.
    – njzk2
    Oct 7, 2014 at 13:22
  • I'm adding my code in this function because I want every app that tries to send an SMS to be intercepted and the popup shown. besides, if I try to add a custom function, I get an error that i'm trying to change the API.
    – Warmaster
    Oct 7, 2014 at 13:26

2 Answers 2

0

You should startActivity for result:

Here are result codes for SmsManager: http://developer.android.com/reference/android/telephony/SmsManager.html

and here you will find some theory about it: How to manage `startActivityForResult` on Android?

3
  • Yes I've seen these. But in the SO link, the data is passed between two activities. I've already thought of startActivityForResult
    – Warmaster
    Oct 7, 2014 at 13:23
  • So can't you startActivityfor result with result STATUS_ON_ICC_SENT and then just override onactivity result? Oct 7, 2014 at 17:16
  • To my understanding result STATUS_ON_ICC_SENT is transmitted when the SMS is stored and sent. I want to display the popup before the SMS is sent. Anyway, maybe I'm not getting it. Can you provide an example?
    – Warmaster
    Oct 8, 2014 at 7:38
0

I found a workaround myself. I'm storing a value in SharedPreferences in my activity and I retrieve it in the SmsManager class. It works for me, but I don't know if it's acceptable from a security point of view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.