I saw many tutorials and StackOverflow discussions about the subject but nothing could help. I may be missing something obvious. So, I'm trying to display a toast message when having an incoming sms.
My manifest looks like this : I tried to put highest priority as advised on another trend, but with no effect :
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver android:name="com.araxide.nottogetherthistime.SMSReceiver" android:exported="true">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
This is SMSReceiver class.
public class SMSReceiver extends BroadcastReceiver {
private final String ACTION_RECEIVE_SMS = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
// Toast.makeText(context, "SMS Received!", Toast.LENGTH_LONG).show();
if (intent.getAction().equals(ACTION_RECEIVE_SMS)) {
Toast.makeText(context, "SMS Received!", Toast.LENGTH_LONG).show();
}
}
}
Should I add something in MainActivity ? Based on the examples I saw, I believe it should work this way. Thanks a lot if you have an idea.