Click here to Skip to main content
15,849,996 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send SMS programmatically using Android Studio. I found the solution.

Now the issue is - API level 23 or latter Google imply some restriction. And sending SMS is marked as "dangerous" permission. But I am not getting any details about that. And also I found so many solutions, but none of them for newer API. Now my question is - can I send SMS? If yes, what is the solution. Please help me.

Thanks in advance.

What I have tried:

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(<PhoneNo>, null, <Text>, null, null);

Added permission SEND_SMS on AndroidManifest.xml:

<uses-permission android:name="android.permission.SEND_SMS" />

And also check permission at runtime:

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED)
    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.SEND_SMS}, 0);
David Crow 19-Jun-23 8:21am    
What does calling sendTextMessage() produce? Do you have a default SMS app?
Tim the Gamer 19-Jun-23 13:25pm    
the code should work but the property SmsManager.Default was deprecated. Try checking with Google Android documentation on how to access an instance of sms manager.
Tim the Gamer 19-Jun-23 14:02pm    
you have any locgcat messages when you try to send the message?
Subrata.In 20-Jun-23 1:21am    
Thanks everyone for valuable comments. I have no issue on code. Just want to know, if I send sms from my app (which is not default app for sms), will it violet any rule? If yes, how to send sms?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900