Android: 如何在没有活动的情况下注册内容观察者?

6
我需要监听所有收发短信并将其存储到文本文件中。为此,我正在使用广播接收器来监听所有传入消息。这个方法很好用。但是对于发送的短信,如何注册内容观察器而不需要activity?我不想在我的应用程序中有任何activity。现在即使在重启后,广播接收器也会继续监听,那么内容观察器是否也会在重启后继续监听?如何合并这两个功能?
以下是我manifest.xml的一部分:
<receiver class="map" android:name=".map" android:enabled="true">

            <intent-filter>

                <action android:value="android.provider.Telephony.SMS_RECEIVED"                   android:name="android.provider.Telephony.SMS_RECEIVED" />

            </intent-filter>

        </receiver>

这里是扩展广播接收器的类。
public class map extends BroadcastReceiver {
    /** Called when the activity is first created. */
    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    public void onReceive(Context context, Intent intent) 
    { 
                  // Here I store the sms in text file

    }

任何帮助都会受到感激。谢谢。
1个回答

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接