android - 没有 list 的 SMS 广播接收器

标签 android android-intent

想知道如何在不使用 list 文件的情况下创建 SMS 广播接收器。例如,这是我当前的 list 文件行:

<receiver android:name="com.paradopolis.randomnotifications.SMSListener">
        <intent-filter>
          <action android:name="android.provider.Telephony.SMS_RECEIVED" />
       </intent-filter>
</receiver>

它工作正常,但我希望能够删除线路并在我的服务中注册我的广播接收器,例如:

registerReceiver(new SMSListener() , [?????]);

但我找不到要使用的 Intent 过滤器,因为 SMS_RECEIVED 是 Telephony 包的一部分。所以问题是:那个 Intent 过滤器是什么?

最佳答案

在你的 java 文件中创建 IntentFilter,然后 registerReceiver(Receiver, IntentFilter)

该操作将 android.provider.Telephony.SMS_RECEIVED 作为字符串。

IntentFilter i = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(new SMSListener() , i);

关于android - 没有 list 的 SMS 广播接收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16182314/

相关文章:

android - 工具栏标题显示在底部

android - Robolectric 给出了一个异常(exception)

Android,以编程方式布局按钮 View ?

android - 如何通过导航 Intent 将多个航路点传递到 android 中的标准谷歌地图应用程序?

java - 四个 Activity 不显示 Toast

java - 用户从图库或自定义相机中选择图像,而不是图像的相机应用程序

android - 如何在按下主页按钮后继续录制?

适用于 Kiosk 设备的 Android 平板电脑或 iPad

java - 在 Intent 中传递的同一个包上使用 putParcelableArrayList 和 putInt

android - 使用带有标志 FLAG_ACTIVITY_NEW_TASK | 的 startactivityforresult | FLAG_ACTIVITY_CLEAR_TASK