I am unable to find android.provider.Telephony
action in android studio for creating an app that can receive SMS
. Almost every article including android developer says that I have to include a intent filter action android.provider.Telephony.SMS_RECEIVE
in manifest file. But I figured out that this action is no more supported by android studio. Please help me
Asked
Active
Viewed 593 times
-1

Akshay
- 2,506
- 4
- 34
- 55
-
Edited question,added tags and improved formatting. – Akshay Sep 08 '17 at 09:13
2 Answers
0
pls try this
// Add this in manifest
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<receiver android:name=".SMSReciver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
//Create new class
public class SMSReciver extends BroadcastReceiver
{
private Context mContext;
@Override
public void onReceive(Context context, Intent intent)
{
mContext = context;
Bundle myBundle = intent.getExtras();
SmsMessage[] messages = null;
String strMessage = "";
String lMessageBody = "", lMessageFrom = "";
if (myBundle != null)
{
Object[] pdus = (Object[]) myBundle.get("pdus");
messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++)
{
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
lMessageFrom = messages[i].getOriginatingAddress();
lMessageBody = messages[i].getMessageBody();
}
}
}
}

Manoj Bhadane
- 607
- 5
- 11
-
I wrote exactly same code but android studio is unable to recognize action tag android.provider.Telephony.SMS_RECEIVED. That's the problem – PADAMNABH ELECTRONICS Sep 08 '17 at 06:10
-
I think action tag is removed from latest APIs. If this is the case than what is alternative option – PADAMNABH ELECTRONICS Sep 08 '17 at 06:12
0
You need to give the permission to your manifest file,
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
Then you should include the intent-filter to your manifest,You should have taken a class that extends BroadcastReceiver write the name of that class as receiver name.In my case it is SMSReceivcer.
<receiver android:name=".SMSReceivcer"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>

Hector Morris
- 118
- 5
-
I wrote exactly same code but android studio is unable to recognize action tag android.provider.Telephony.SMS_RECEIVED. That's the problem – PADAMNABH ELECTRONICS Sep 08 '17 at 08:31
-
You should use API level above 19 try to make it 21 or above it. – Hector Morris Sep 08 '17 at 08:58