androidsmssmsmanagerandroid-sms

Get Notified When SMS is sent or cancelled?


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?


Solution

  • 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.