[英]BroadcastReceiver OnReceive() not firing
I saw many tutorials and StackOverflow discussions about the subject but nothing could help.我看到了很多关于这个主题的教程和 StackOverflow 讨论,但没有任何帮助。 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.这是 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?我应该在 MainActivity 中添加一些东西吗? Based on the examples I saw, I believe it should work this way.根据我看到的示例,我相信它应该以这种方式工作。 Thanks a lot if you have an idea.非常感谢,如果你有一个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.