PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] how to intent to native app after sending message from inbuilt message app

 July 12, 2022     android, message, sms     No comments   

Issue

Am using inbuilt message application in my app to send message, but after sending message it stuck there only,while sending message it should intent back to my application how can i do it.

 public void sendSmsIntent(String phoneNumber) {
            Intent intent2 = new Intent(Intent.ACTION_SENDTO);
            intent2.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
            startActivity(intent2);

        }

Solution

Call sendSMS() method wherever you want to send SMS;

 private void sendSMS()
        {

            PendingIntent sent = this.createPendingResult(SENT, new Intent(),   PendingIntent.FLAG_UPDATE_CURRENT);


            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendDataMessage(strcontactnumber, null, SMS_PORT, messageText.getBytes(), sent, null);
        }

onActivityResult();

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    String toast = null;
    switch (requestCode)
    {
    case SENT :
        switch (resultCode)
        {
        case RESULT_OK :
            toast = "OK";
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE :
            toast = "Generic Failure";
            break;
        case SmsManager.RESULT_ERROR_RADIO_OFF :
            toast = "Radio Off";
            break;
        case SmsManager.RESULT_ERROR_NULL_PDU :
            toast = "Null Pdu";
            break;
        }
        break;
    }

    if (toast != null)
    {
        Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
    }
}

It will directly send sms from your app without calling native app

And if you want to return back to your app by your code then

It is possible. Just need to add the following extra to your intent:

sendIntent.putExtra("exit_on_sent", true);


Answered By - KishuDroid
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing