0

My app is allowed to send only one SMS per day using the default SMS sender ( which is already present in every android device ), as a result, I need to disable send SMS button once the SMS is sent.

What I am doing currently is, whenever a user clicks on send SMS button, I navigate him to the device default message sender like this,

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", phoneNumber, null));
        intent.putExtra("sms_body", message);
        baseActivity.startActivity(intent);

I can only navigate the user to default SMS sender and then from there the user can either send SMS or he can cancel sending SMS ( by pressing back button ), now the question is how will I be notified that the SMS is sent? Is there any callback or receiver mechanism which can tell me that the SMS was sent or SMS was canceled by the user?

iCantC
  • 2,852
  • 1
  • 19
  • 34

1 Answers1

0

which is already present in every android device

Not really.

I navigate him to the device default message sender like this,

There is no requirement for an Android device to have an app that responds to ACTION_VIEW for the sms scheme. You will have a better chance with ACTION_SEND, as that is what Google says that you should use.

Even then, there will be devices that lack such an app. For example, not all Android devices are phones.

how will I be notified that the SMS is sent?

You won't. What the user does in response to your ACTION_VIEW (or ACTION_SEND, ACTION_SENDTO, or ACTION_SEND_MULTIPLE) request is up to the user and the user's chosen app.

Is there any callback or receiver mechanism which can tell me that the SMS was sent or SMS was canceled by the user?

Not really. For starters, the user might not choose an SMS client to respond to your Intent. After all, any app can have an activity that responds to your Intent structure. Even if the user chooses an SMS client, there is no guarantee that the app will do anything that allows third parties (like your app) to know about what goes on inside that app.

Many, but not all, SMS clients will update the system supplied Sms content provider with the sent item.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Which means I am doomed. – iCantC Mar 26 '20 at 12:43
  • @iCantC: I definitely do not see how you can enforce a one SMS *sent* per day limit. You can enforce a one SMS *requested* per day limit, as you are the one making the request. – CommonsWare Mar 26 '20 at 12:48
  • I'm not running the show, it's the mighty Business People. One more caveat, changing ACTION_VIEW to ACTION_SEND crashes my application, so as of now I have reverted back to ACTION_VIEW. – iCantC Mar 26 '20 at 12:53
  • @iCantC: "changing ACTION_VIEW to ACTION_SEND crashes my application" -- then perhaps you should open up a separate Stack Overflow question with a [mcve] showing your code and the stack trace. "I'm not running the show, it's the mighty Business People" -- switch to using a Web service for sending the SMS (e.g., Twilio). – CommonsWare Mar 26 '20 at 12:57
  • My Bad was setting scheme "sms" for Intent Action "ACTION_SENDTO", changed scheme to "smsto" and worked just fine. I'll suggest the business guys about Twilio, certainly looks interesting – iCantC Mar 26 '20 at 13:24