Karan
Karan

Reputation: 497

clear USSD response Messages from screen

I am calling on USSD number using this

String ussdCode = "*" + "123" + Uri.encode("#");

startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));

But it shows the response message on screen . How can I clear these messages from the screen??

Thanks in advance

Upvotes: 0

Views: 2933

Answers (1)

Yury
Yury

Reputation: 20936

This is not my solution. It is taken from here. If you know Russian you can read the whole article there. However here is their solition:

import com.example.android.UssdMessage.USSD;



public class UssdmessageActivity extends Activity implements OnClickListener {
        /** Called when the activity is first created. */
        private TextView view;
        private AutoCompleteTextView number;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                Button button = (Button) findViewById(R.id.button1);
                button.setOnClickListener(this);
                this.view = (TextView) findViewById(R.id.Text2);
                this.number = (AutoCompleteTextView) findViewById(R.id.Text1);
        }

        @Override
        public void onClick(View arg0) {
                String encodedHash = Uri.encode("#");
                call("*" + number.getText() + encodedHash);
                this.view.setText("");
        }

        protected void call(String phoneNumber) {
                try {
                        startActivityForResult(
                                        new Intent("android.intent.action.CALL", Uri.parse("tel:"
                                                        + phoneNumber)), 1);
                } catch (Exception eExcept) {
                        this.view.append("\n\n " + "\n" + eExcept.toString());
                }
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                USSD ussd = new USSD(4000,4000); // передается два параметра, задержка до и после (ms) создания сообщения
                if (ussd.IsFound())
                        this.view.append("\n"+ussd.getMsg());
                else
                        this.view.append(""+R.string.error_ussd_msg);
        }
}

They rely on this class for ussd parsing.

After implementing this activity you can clear the TextView with the ussd message. Or you can finish an activity.

Upvotes: 2

Related Questions