How can i receive data of incoming message using broadcast receiver in Oreo, its working perfect in before Oreo version,but i am unable to receive in Oreo, i have trying to short out this by help of developer site but there is not any sample code for this only Oreo limitation is given there
Here is my BroadCast Receiver Class
public class SMSReceiver extends BroadcastReceiver
{
String sender,message;
public void onReceive(Context context, Intent intent) {
Bundle myBundle = intent.getExtras();
SmsMessage[] messages = null;
String strMessage = "";
if (myBundle != null) {
Object[] pdus = (Object[]) myBundle.get("pdus");
messages = new SmsMessage[pdus.length];
SmsMessage shortMessage=SmsMessage.createFromPdu((byte[]) pdus[0]);
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sender=messages[i].getOriginatingAddress();
String message =shortMessage.getMessageBody();
Toast.makeText(context, sender+"\n"+message, Toast.LENGTH_SHORT).show();
}
}
}
and here is my Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SMSReceiver" android:enabled="true" android:exported="true">
<intent-filter
android:priority="1000"
>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</service>
</application>