Restrict sending message second time in Android

121 views Asked by At

I am sending sms to a number from my app. I want to restrict my app to send SMS second time. How can I do this? I have tried to uninstall the app but it requires user permission which I don't want. I have tried this so far but could not get success. Here is my code:

code snippet

registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    SMSisSend = true;
/*how to handle here to restrict to send additional msg.*/
                    break;
                case Activity.RESULT_CANCELED:
                    break;
                }
            }
        }, new IntentFilter(DELIVERED));
1

There are 1 answers

1
NullByte On BEST ANSWER
  1. IF sms successfully delivered set Flag true in SharedPrefs
  2. Check if Flag exist in SharedPrefs, if yes dont execute sms sending code.